{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 投资组合 Portfolio"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 177,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np # 数据处理最重要的模块\n",
    "import pandas as pd # 数据处理最重要的模块\n",
    "import scipy.stats as stats # 统计模块\n",
    "import scipy\n",
    "# import pymysql  # 导入数据库模块\n",
    "\n",
    "from datetime import datetime # 时间模块\n",
    "import statsmodels.formula.api as smf  # OLS regression\n",
    "\n",
    "# import pyreadr # read RDS file\n",
    "\n",
    "from matplotlib import style\n",
    "import matplotlib.pyplot as plt  # 画图模块\n",
    "import matplotlib.dates as mdates\n",
    "\n",
    "from matplotlib.font_manager import FontProperties # 作图中文\n",
    "from pylab import mpl\n",
    "#mpl.rcParams['font.sans-serif'] = ['SimHei']\n",
    "#plt.rcParams['font.family'] = 'Times New Roman'\n",
    "\n",
    "#输出矢量图 渲染矢量图\n",
    "%matplotlib inline\n",
    "%config InlineBackend.figure_format = 'svg'\n",
    "\n",
    "from IPython.core.interactiveshell import InteractiveShell # jupyter运行输出的模块\n",
    "#显示每一个运行结果\n",
    "InteractiveShell.ast_node_interactivity = 'all'\n",
    "\n",
    "#设置行不限制数量\n",
    "#pd.set_option('display.max_rows',None)\n",
    "\n",
    "#设置列不限制数量\n",
    "pd.set_option('display.max_columns', None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 178,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Stkcd</th>\n",
       "      <th>month</th>\n",
       "      <th>price</th>\n",
       "      <th>Rank</th>\n",
       "      <th>Freq</th>\n",
       "      <th>floatingvalue</th>\n",
       "      <th>totalvalue</th>\n",
       "      <th>sizef</th>\n",
       "      <th>sizet</th>\n",
       "      <th>Return</th>\n",
       "      <th>rfmonth</th>\n",
       "      <th>ret</th>\n",
       "      <th>next_ret</th>\n",
       "      <th>w</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-05-31</td>\n",
       "      <td>38.34</td>\n",
       "      <td>2</td>\n",
       "      <td>24.0</td>\n",
       "      <td>1.016010e+09</td>\n",
       "      <td>1.859497e+09</td>\n",
       "      <td>20.739149</td>\n",
       "      <td>21.343572</td>\n",
       "      <td>-0.122253</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.128345</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-06-30</td>\n",
       "      <td>33.99</td>\n",
       "      <td>3</td>\n",
       "      <td>23.0</td>\n",
       "      <td>9.007350e+08</td>\n",
       "      <td>1.648521e+09</td>\n",
       "      <td>20.618722</td>\n",
       "      <td>21.223144</td>\n",
       "      <td>-0.113459</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>-0.137013</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-07-31</td>\n",
       "      <td>29.54</td>\n",
       "      <td>4</td>\n",
       "      <td>16.0</td>\n",
       "      <td>7.828100e+08</td>\n",
       "      <td>1.432695e+09</td>\n",
       "      <td>20.478401</td>\n",
       "      <td>21.082823</td>\n",
       "      <td>-0.130921</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.137013</td>\n",
       "      <td>-0.417680</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-08-31</td>\n",
       "      <td>15.00</td>\n",
       "      <td>5</td>\n",
       "      <td>15.0</td>\n",
       "      <td>6.748338e+08</td>\n",
       "      <td>1.346275e+09</td>\n",
       "      <td>20.329977</td>\n",
       "      <td>21.020607</td>\n",
       "      <td>-0.411588</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.417680</td>\n",
       "      <td>-0.039425</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-09-30</td>\n",
       "      <td>14.50</td>\n",
       "      <td>6</td>\n",
       "      <td>24.0</td>\n",
       "      <td>6.523394e+08</td>\n",
       "      <td>1.301399e+09</td>\n",
       "      <td>20.296075</td>\n",
       "      <td>20.986706</td>\n",
       "      <td>-0.033333</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.039425</td>\n",
       "      <td>0.849080</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>752023</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-08-31</td>\n",
       "      <td>13.56</td>\n",
       "      <td>24</td>\n",
       "      <td>23.0</td>\n",
       "      <td>7.955351e+09</td>\n",
       "      <td>1.054667e+10</td>\n",
       "      <td>22.797111</td>\n",
       "      <td>23.079076</td>\n",
       "      <td>-0.025862</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.027103</td>\n",
       "      <td>0.071030</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>752024</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-09-30</td>\n",
       "      <td>14.54</td>\n",
       "      <td>25</td>\n",
       "      <td>20.0</td>\n",
       "      <td>8.530295e+09</td>\n",
       "      <td>1.130889e+10</td>\n",
       "      <td>22.866890</td>\n",
       "      <td>23.148855</td>\n",
       "      <td>0.072271</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>0.071030</td>\n",
       "      <td>-0.048696</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>752025</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-10-31</td>\n",
       "      <td>13.85</td>\n",
       "      <td>26</td>\n",
       "      <td>17.0</td>\n",
       "      <td>8.125488e+09</td>\n",
       "      <td>1.077222e+10</td>\n",
       "      <td>22.818272</td>\n",
       "      <td>23.100237</td>\n",
       "      <td>-0.047455</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.048696</td>\n",
       "      <td>-0.027956</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>752026</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-11-30</td>\n",
       "      <td>13.48</td>\n",
       "      <td>27</td>\n",
       "      <td>22.0</td>\n",
       "      <td>7.908417e+09</td>\n",
       "      <td>1.048444e+10</td>\n",
       "      <td>22.791193</td>\n",
       "      <td>23.073159</td>\n",
       "      <td>-0.026715</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.027956</td>\n",
       "      <td>0.103358</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>752027</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>14.89</td>\n",
       "      <td>28</td>\n",
       "      <td>21.0</td>\n",
       "      <td>8.735632e+09</td>\n",
       "      <td>1.158111e+10</td>\n",
       "      <td>22.890676</td>\n",
       "      <td>23.172641</td>\n",
       "      <td>0.104599</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>0.103358</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>709883 rows × 14 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         Stkcd      month  price  Rank  Freq  floatingvalue    totalvalue  \\\n",
       "1       000001 1991-05-31  38.34     2  24.0   1.016010e+09  1.859497e+09   \n",
       "2       000001 1991-06-30  33.99     3  23.0   9.007350e+08  1.648521e+09   \n",
       "3       000001 1991-07-31  29.54     4  16.0   7.828100e+08  1.432695e+09   \n",
       "4       000001 1991-08-31  15.00     5  15.0   6.748338e+08  1.346275e+09   \n",
       "5       000001 1991-09-30  14.50     6  24.0   6.523394e+08  1.301399e+09   \n",
       "...        ...        ...    ...   ...   ...            ...           ...   \n",
       "752023  605599 2023-08-31  13.56    24  23.0   7.955351e+09  1.054667e+10   \n",
       "752024  605599 2023-09-30  14.54    25  20.0   8.530295e+09  1.130889e+10   \n",
       "752025  605599 2023-10-31  13.85    26  17.0   8.125488e+09  1.077222e+10   \n",
       "752026  605599 2023-11-30  13.48    27  22.0   7.908417e+09  1.048444e+10   \n",
       "752027  605599 2023-12-31  14.89    28  21.0   8.735632e+09  1.158111e+10   \n",
       "\n",
       "            sizef      sizet    Return   rfmonth       ret  next_ret  w  \n",
       "1       20.739149  21.343572 -0.122253  0.006092 -0.128345 -0.119551  1  \n",
       "2       20.618722  21.223144 -0.113459  0.006092 -0.119551 -0.137013  1  \n",
       "3       20.478401  21.082823 -0.130921  0.006092 -0.137013 -0.417680  1  \n",
       "4       20.329977  21.020607 -0.411588  0.006092 -0.417680 -0.039425  1  \n",
       "5       20.296075  20.986706 -0.033333  0.006092 -0.039425  0.849080  1  \n",
       "...           ...        ...       ...       ...       ...       ... ..  \n",
       "752023  22.797111  23.079076 -0.025862  0.001241 -0.027103  0.071030  1  \n",
       "752024  22.866890  23.148855  0.072271  0.001241  0.071030 -0.048696  1  \n",
       "752025  22.818272  23.100237 -0.047455  0.001241 -0.048696 -0.027956  1  \n",
       "752026  22.791193  23.073159 -0.026715  0.001241 -0.027956  0.103358  1  \n",
       "752027  22.890676  23.172641  0.104599  0.001241  0.103358       NaN  1  \n",
       "\n",
       "[709883 rows x 14 columns]"
      ]
     },
     "execution_count": 178,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cross = pd.read_csv('datasets/ret_mon_python2023.csv')\n",
    "from pandas.tseries.offsets import MonthEnd\n",
    "cross['month'] = pd.to_datetime(cross['month'], format='%Y-%m-%d') + MonthEnd(1)\n",
    "# 补齐股票代码 如果不满6位 在前面补上0\n",
    "cross['Stkcd'] = cross['Stkcd'].apply(lambda x: '{:0>6}'.format(x)) # 6位股票代码\n",
    "cross['w'] = 1\n",
    "cross = cross.dropna(subset=['ret'])\n",
    "cross"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 短期动量 Momentum\n",
    "短期反转reversal"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 在每个月$t$把所有的股票按照这个月收益率的大小分10组，最高收益率叫Pmax，最低收益率叫P1\n",
    "- 月末持有P1，卖出PMAX\n",
    "- 观察投资组合在$t+1$月的表现\n",
    "\n",
    "\n",
    "真正的动量：\n",
    "- 在$t$月，计算股票$t-36$到$t-1$的累计收益率 把所有股票按照这个累计收益率的大小分1组\n",
    "- 月末持有PMAX，卖出P1\n",
    "- 观察投资组合在$t+1$月的表现"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 策略细节"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 179,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>ret</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">1991-01-31</th>\n",
       "      <th>0.1</th>\n",
       "      <td>-0.002031</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.2</th>\n",
       "      <td>0.002868</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.3</th>\n",
       "      <td>0.006672</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.4</th>\n",
       "      <td>0.010476</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.5</th>\n",
       "      <td>0.022318</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">2023-12-31</th>\n",
       "      <th>0.5</th>\n",
       "      <td>-0.030481</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.6</th>\n",
       "      <td>-0.019060</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.7</th>\n",
       "      <td>-0.003987</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.8</th>\n",
       "      <td>0.016061</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.9</th>\n",
       "      <td>0.058594</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3564 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                     ret\n",
       "month                   \n",
       "1991-01-31 0.1 -0.002031\n",
       "           0.2  0.002868\n",
       "           0.3  0.006672\n",
       "           0.4  0.010476\n",
       "           0.5  0.022318\n",
       "...                  ...\n",
       "2023-12-31 0.5 -0.030481\n",
       "           0.6 -0.019060\n",
       "           0.7 -0.003987\n",
       "           0.8  0.016061\n",
       "           0.9  0.058594\n",
       "\n",
       "[3564 rows x 1 columns]"
      ]
     },
     "execution_count": 179,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fenweishu = pd.DataFrame(\n",
    "    cross.groupby(['month'])['ret'].quantile([0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9]))\n",
    "fenweishu"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 180,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>month</th>\n",
       "      <th>level_1</th>\n",
       "      <th>ret</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1991-01-31</td>\n",
       "      <td>0.1</td>\n",
       "      <td>-0.002031</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1991-01-31</td>\n",
       "      <td>0.2</td>\n",
       "      <td>0.002868</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1991-01-31</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0.006672</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1991-01-31</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.010476</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1991-01-31</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.022318</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3559</th>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>0.5</td>\n",
       "      <td>-0.030481</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3560</th>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>0.6</td>\n",
       "      <td>-0.019060</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3561</th>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>0.7</td>\n",
       "      <td>-0.003987</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3562</th>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>0.8</td>\n",
       "      <td>0.016061</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3563</th>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>0.9</td>\n",
       "      <td>0.058594</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3564 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          month  level_1       ret\n",
       "0    1991-01-31      0.1 -0.002031\n",
       "1    1991-01-31      0.2  0.002868\n",
       "2    1991-01-31      0.3  0.006672\n",
       "3    1991-01-31      0.4  0.010476\n",
       "4    1991-01-31      0.5  0.022318\n",
       "...         ...      ...       ...\n",
       "3559 2023-12-31      0.5 -0.030481\n",
       "3560 2023-12-31      0.6 -0.019060\n",
       "3561 2023-12-31      0.7 -0.003987\n",
       "3562 2023-12-31      0.8  0.016061\n",
       "3563 2023-12-31      0.9  0.058594\n",
       "\n",
       "[3564 rows x 3 columns]"
      ]
     },
     "execution_count": 180,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fenweishu=fenweishu.reset_index()\n",
    "fenweishu"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 181,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>level_1</th>\n",
       "      <th>0.1</th>\n",
       "      <th>0.2</th>\n",
       "      <th>0.3</th>\n",
       "      <th>0.4</th>\n",
       "      <th>0.5</th>\n",
       "      <th>0.6</th>\n",
       "      <th>0.7</th>\n",
       "      <th>0.8</th>\n",
       "      <th>0.9</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1991-01-31</th>\n",
       "      <td>-0.002031</td>\n",
       "      <td>0.002868</td>\n",
       "      <td>0.006672</td>\n",
       "      <td>0.010476</td>\n",
       "      <td>0.022318</td>\n",
       "      <td>0.034159</td>\n",
       "      <td>0.044819</td>\n",
       "      <td>0.055479</td>\n",
       "      <td>0.068586</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-02-28</th>\n",
       "      <td>-0.042360</td>\n",
       "      <td>-0.037753</td>\n",
       "      <td>-0.012489</td>\n",
       "      <td>0.005470</td>\n",
       "      <td>0.019315</td>\n",
       "      <td>0.030097</td>\n",
       "      <td>0.034615</td>\n",
       "      <td>0.046888</td>\n",
       "      <td>0.081973</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-03-31</th>\n",
       "      <td>-0.133314</td>\n",
       "      <td>-0.133261</td>\n",
       "      <td>-0.127661</td>\n",
       "      <td>-0.092379</td>\n",
       "      <td>-0.069797</td>\n",
       "      <td>-0.065144</td>\n",
       "      <td>-0.054707</td>\n",
       "      <td>-0.030694</td>\n",
       "      <td>0.028608</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-04-30</th>\n",
       "      <td>-0.124371</td>\n",
       "      <td>-0.122867</td>\n",
       "      <td>-0.109328</td>\n",
       "      <td>-0.100079</td>\n",
       "      <td>-0.087628</td>\n",
       "      <td>-0.046745</td>\n",
       "      <td>0.020729</td>\n",
       "      <td>0.073833</td>\n",
       "      <td>0.090508</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-05-31</th>\n",
       "      <td>-0.129118</td>\n",
       "      <td>-0.128345</td>\n",
       "      <td>-0.120582</td>\n",
       "      <td>-0.036993</td>\n",
       "      <td>-0.031989</td>\n",
       "      <td>-0.006657</td>\n",
       "      <td>0.055289</td>\n",
       "      <td>0.080639</td>\n",
       "      <td>0.202117</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-08-31</th>\n",
       "      <td>-0.127963</td>\n",
       "      <td>-0.101104</td>\n",
       "      <td>-0.081604</td>\n",
       "      <td>-0.067501</td>\n",
       "      <td>-0.053251</td>\n",
       "      <td>-0.037892</td>\n",
       "      <td>-0.019222</td>\n",
       "      <td>0.004010</td>\n",
       "      <td>0.046254</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-09-30</th>\n",
       "      <td>-0.077841</td>\n",
       "      <td>-0.048326</td>\n",
       "      <td>-0.030102</td>\n",
       "      <td>-0.016111</td>\n",
       "      <td>-0.004367</td>\n",
       "      <td>0.005559</td>\n",
       "      <td>0.017018</td>\n",
       "      <td>0.033242</td>\n",
       "      <td>0.066314</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-10-31</th>\n",
       "      <td>-0.104815</td>\n",
       "      <td>-0.070334</td>\n",
       "      <td>-0.049764</td>\n",
       "      <td>-0.033905</td>\n",
       "      <td>-0.020315</td>\n",
       "      <td>-0.006363</td>\n",
       "      <td>0.010970</td>\n",
       "      <td>0.035557</td>\n",
       "      <td>0.078925</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-11-30</th>\n",
       "      <td>-0.050131</td>\n",
       "      <td>-0.024692</td>\n",
       "      <td>-0.007101</td>\n",
       "      <td>0.006883</td>\n",
       "      <td>0.020630</td>\n",
       "      <td>0.034527</td>\n",
       "      <td>0.050795</td>\n",
       "      <td>0.075465</td>\n",
       "      <td>0.123638</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-31</th>\n",
       "      <td>-0.096007</td>\n",
       "      <td>-0.070909</td>\n",
       "      <td>-0.055072</td>\n",
       "      <td>-0.042784</td>\n",
       "      <td>-0.030481</td>\n",
       "      <td>-0.019060</td>\n",
       "      <td>-0.003987</td>\n",
       "      <td>0.016061</td>\n",
       "      <td>0.058594</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>396 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "level_1          0.1       0.2       0.3       0.4       0.5       0.6  \\\n",
       "month                                                                    \n",
       "1991-01-31 -0.002031  0.002868  0.006672  0.010476  0.022318  0.034159   \n",
       "1991-02-28 -0.042360 -0.037753 -0.012489  0.005470  0.019315  0.030097   \n",
       "1991-03-31 -0.133314 -0.133261 -0.127661 -0.092379 -0.069797 -0.065144   \n",
       "1991-04-30 -0.124371 -0.122867 -0.109328 -0.100079 -0.087628 -0.046745   \n",
       "1991-05-31 -0.129118 -0.128345 -0.120582 -0.036993 -0.031989 -0.006657   \n",
       "...              ...       ...       ...       ...       ...       ...   \n",
       "2023-08-31 -0.127963 -0.101104 -0.081604 -0.067501 -0.053251 -0.037892   \n",
       "2023-09-30 -0.077841 -0.048326 -0.030102 -0.016111 -0.004367  0.005559   \n",
       "2023-10-31 -0.104815 -0.070334 -0.049764 -0.033905 -0.020315 -0.006363   \n",
       "2023-11-30 -0.050131 -0.024692 -0.007101  0.006883  0.020630  0.034527   \n",
       "2023-12-31 -0.096007 -0.070909 -0.055072 -0.042784 -0.030481 -0.019060   \n",
       "\n",
       "level_1          0.7       0.8       0.9  \n",
       "month                                     \n",
       "1991-01-31  0.044819  0.055479  0.068586  \n",
       "1991-02-28  0.034615  0.046888  0.081973  \n",
       "1991-03-31 -0.054707 -0.030694  0.028608  \n",
       "1991-04-30  0.020729  0.073833  0.090508  \n",
       "1991-05-31  0.055289  0.080639  0.202117  \n",
       "...              ...       ...       ...  \n",
       "2023-08-31 -0.019222  0.004010  0.046254  \n",
       "2023-09-30  0.017018  0.033242  0.066314  \n",
       "2023-10-31  0.010970  0.035557  0.078925  \n",
       "2023-11-30  0.050795  0.075465  0.123638  \n",
       "2023-12-31 -0.003987  0.016061  0.058594  \n",
       "\n",
       "[396 rows x 9 columns]"
      ]
     },
     "execution_count": 181,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数据变形数据长变宽\n",
    "# 数据变形 数据宽变长 melt\n",
    "fenweishu=fenweishu.pivot(index='month',columns='level_1',values='ret')\n",
    "fenweishu"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 182,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>one</th>\n",
       "      <th>two</th>\n",
       "      <th>three</th>\n",
       "      <th>four</th>\n",
       "      <th>five</th>\n",
       "      <th>six</th>\n",
       "      <th>seven</th>\n",
       "      <th>eight</th>\n",
       "      <th>nine</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1991-01-31</th>\n",
       "      <td>-0.002031</td>\n",
       "      <td>0.002868</td>\n",
       "      <td>0.006672</td>\n",
       "      <td>0.010476</td>\n",
       "      <td>0.022318</td>\n",
       "      <td>0.034159</td>\n",
       "      <td>0.044819</td>\n",
       "      <td>0.055479</td>\n",
       "      <td>0.068586</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-02-28</th>\n",
       "      <td>-0.042360</td>\n",
       "      <td>-0.037753</td>\n",
       "      <td>-0.012489</td>\n",
       "      <td>0.005470</td>\n",
       "      <td>0.019315</td>\n",
       "      <td>0.030097</td>\n",
       "      <td>0.034615</td>\n",
       "      <td>0.046888</td>\n",
       "      <td>0.081973</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-03-31</th>\n",
       "      <td>-0.133314</td>\n",
       "      <td>-0.133261</td>\n",
       "      <td>-0.127661</td>\n",
       "      <td>-0.092379</td>\n",
       "      <td>-0.069797</td>\n",
       "      <td>-0.065144</td>\n",
       "      <td>-0.054707</td>\n",
       "      <td>-0.030694</td>\n",
       "      <td>0.028608</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-04-30</th>\n",
       "      <td>-0.124371</td>\n",
       "      <td>-0.122867</td>\n",
       "      <td>-0.109328</td>\n",
       "      <td>-0.100079</td>\n",
       "      <td>-0.087628</td>\n",
       "      <td>-0.046745</td>\n",
       "      <td>0.020729</td>\n",
       "      <td>0.073833</td>\n",
       "      <td>0.090508</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-05-31</th>\n",
       "      <td>-0.129118</td>\n",
       "      <td>-0.128345</td>\n",
       "      <td>-0.120582</td>\n",
       "      <td>-0.036993</td>\n",
       "      <td>-0.031989</td>\n",
       "      <td>-0.006657</td>\n",
       "      <td>0.055289</td>\n",
       "      <td>0.080639</td>\n",
       "      <td>0.202117</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-08-31</th>\n",
       "      <td>-0.127963</td>\n",
       "      <td>-0.101104</td>\n",
       "      <td>-0.081604</td>\n",
       "      <td>-0.067501</td>\n",
       "      <td>-0.053251</td>\n",
       "      <td>-0.037892</td>\n",
       "      <td>-0.019222</td>\n",
       "      <td>0.004010</td>\n",
       "      <td>0.046254</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-09-30</th>\n",
       "      <td>-0.077841</td>\n",
       "      <td>-0.048326</td>\n",
       "      <td>-0.030102</td>\n",
       "      <td>-0.016111</td>\n",
       "      <td>-0.004367</td>\n",
       "      <td>0.005559</td>\n",
       "      <td>0.017018</td>\n",
       "      <td>0.033242</td>\n",
       "      <td>0.066314</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-10-31</th>\n",
       "      <td>-0.104815</td>\n",
       "      <td>-0.070334</td>\n",
       "      <td>-0.049764</td>\n",
       "      <td>-0.033905</td>\n",
       "      <td>-0.020315</td>\n",
       "      <td>-0.006363</td>\n",
       "      <td>0.010970</td>\n",
       "      <td>0.035557</td>\n",
       "      <td>0.078925</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-11-30</th>\n",
       "      <td>-0.050131</td>\n",
       "      <td>-0.024692</td>\n",
       "      <td>-0.007101</td>\n",
       "      <td>0.006883</td>\n",
       "      <td>0.020630</td>\n",
       "      <td>0.034527</td>\n",
       "      <td>0.050795</td>\n",
       "      <td>0.075465</td>\n",
       "      <td>0.123638</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-31</th>\n",
       "      <td>-0.096007</td>\n",
       "      <td>-0.070909</td>\n",
       "      <td>-0.055072</td>\n",
       "      <td>-0.042784</td>\n",
       "      <td>-0.030481</td>\n",
       "      <td>-0.019060</td>\n",
       "      <td>-0.003987</td>\n",
       "      <td>0.016061</td>\n",
       "      <td>0.058594</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>396 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                 one       two     three      four      five       six  \\\n",
       "month                                                                    \n",
       "1991-01-31 -0.002031  0.002868  0.006672  0.010476  0.022318  0.034159   \n",
       "1991-02-28 -0.042360 -0.037753 -0.012489  0.005470  0.019315  0.030097   \n",
       "1991-03-31 -0.133314 -0.133261 -0.127661 -0.092379 -0.069797 -0.065144   \n",
       "1991-04-30 -0.124371 -0.122867 -0.109328 -0.100079 -0.087628 -0.046745   \n",
       "1991-05-31 -0.129118 -0.128345 -0.120582 -0.036993 -0.031989 -0.006657   \n",
       "...              ...       ...       ...       ...       ...       ...   \n",
       "2023-08-31 -0.127963 -0.101104 -0.081604 -0.067501 -0.053251 -0.037892   \n",
       "2023-09-30 -0.077841 -0.048326 -0.030102 -0.016111 -0.004367  0.005559   \n",
       "2023-10-31 -0.104815 -0.070334 -0.049764 -0.033905 -0.020315 -0.006363   \n",
       "2023-11-30 -0.050131 -0.024692 -0.007101  0.006883  0.020630  0.034527   \n",
       "2023-12-31 -0.096007 -0.070909 -0.055072 -0.042784 -0.030481 -0.019060   \n",
       "\n",
       "               seven     eight      nine  \n",
       "month                                     \n",
       "1991-01-31  0.044819  0.055479  0.068586  \n",
       "1991-02-28  0.034615  0.046888  0.081973  \n",
       "1991-03-31 -0.054707 -0.030694  0.028608  \n",
       "1991-04-30  0.020729  0.073833  0.090508  \n",
       "1991-05-31  0.055289  0.080639  0.202117  \n",
       "...              ...       ...       ...  \n",
       "2023-08-31 -0.019222  0.004010  0.046254  \n",
       "2023-09-30  0.017018  0.033242  0.066314  \n",
       "2023-10-31  0.010970  0.035557  0.078925  \n",
       "2023-11-30  0.050795  0.075465  0.123638  \n",
       "2023-12-31 -0.003987  0.016061  0.058594  \n",
       "\n",
       "[396 rows x 9 columns]"
      ]
     },
     "execution_count": 182,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fenweishu.columns=['one','two','three','four','five','six','seven','eight','nine']# 改变标签名\n",
    "fenweishu"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 合并回原来的数据表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 183,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Stkcd</th>\n",
       "      <th>month</th>\n",
       "      <th>price</th>\n",
       "      <th>Rank</th>\n",
       "      <th>Freq</th>\n",
       "      <th>floatingvalue</th>\n",
       "      <th>totalvalue</th>\n",
       "      <th>sizef</th>\n",
       "      <th>sizet</th>\n",
       "      <th>Return</th>\n",
       "      <th>rfmonth</th>\n",
       "      <th>ret</th>\n",
       "      <th>next_ret</th>\n",
       "      <th>w</th>\n",
       "      <th>one</th>\n",
       "      <th>two</th>\n",
       "      <th>three</th>\n",
       "      <th>four</th>\n",
       "      <th>five</th>\n",
       "      <th>six</th>\n",
       "      <th>seven</th>\n",
       "      <th>eight</th>\n",
       "      <th>nine</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-05-31</td>\n",
       "      <td>38.34</td>\n",
       "      <td>2</td>\n",
       "      <td>24.0</td>\n",
       "      <td>1.016010e+09</td>\n",
       "      <td>1.859497e+09</td>\n",
       "      <td>20.739149</td>\n",
       "      <td>21.343572</td>\n",
       "      <td>-0.122253</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.128345</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.129118</td>\n",
       "      <td>-0.128345</td>\n",
       "      <td>-0.120582</td>\n",
       "      <td>-0.036993</td>\n",
       "      <td>-0.031989</td>\n",
       "      <td>-0.006657</td>\n",
       "      <td>0.055289</td>\n",
       "      <td>0.080639</td>\n",
       "      <td>0.202117</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-06-30</td>\n",
       "      <td>33.99</td>\n",
       "      <td>3</td>\n",
       "      <td>23.0</td>\n",
       "      <td>9.007350e+08</td>\n",
       "      <td>1.648521e+09</td>\n",
       "      <td>20.618722</td>\n",
       "      <td>21.223144</td>\n",
       "      <td>-0.113459</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>-0.137013</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.309901</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>-0.115097</td>\n",
       "      <td>0.166237</td>\n",
       "      <td>0.177858</td>\n",
       "      <td>0.184748</td>\n",
       "      <td>0.190006</td>\n",
       "      <td>0.190283</td>\n",
       "      <td>0.201980</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-07-31</td>\n",
       "      <td>29.54</td>\n",
       "      <td>4</td>\n",
       "      <td>16.0</td>\n",
       "      <td>7.828100e+08</td>\n",
       "      <td>1.432695e+09</td>\n",
       "      <td>20.478401</td>\n",
       "      <td>21.082823</td>\n",
       "      <td>-0.130921</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.137013</td>\n",
       "      <td>-0.417680</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.244184</td>\n",
       "      <td>-0.128701</td>\n",
       "      <td>-0.086966</td>\n",
       "      <td>-0.052277</td>\n",
       "      <td>0.007620</td>\n",
       "      <td>0.067451</td>\n",
       "      <td>0.149691</td>\n",
       "      <td>0.216426</td>\n",
       "      <td>0.246553</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-08-31</td>\n",
       "      <td>15.00</td>\n",
       "      <td>5</td>\n",
       "      <td>15.0</td>\n",
       "      <td>6.748338e+08</td>\n",
       "      <td>1.346275e+09</td>\n",
       "      <td>20.329977</td>\n",
       "      <td>21.020607</td>\n",
       "      <td>-0.411588</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.417680</td>\n",
       "      <td>-0.039425</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.161430</td>\n",
       "      <td>-0.110028</td>\n",
       "      <td>-0.049934</td>\n",
       "      <td>-0.014296</td>\n",
       "      <td>0.018298</td>\n",
       "      <td>0.060859</td>\n",
       "      <td>0.219168</td>\n",
       "      <td>0.233226</td>\n",
       "      <td>0.238218</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-09-30</td>\n",
       "      <td>14.50</td>\n",
       "      <td>6</td>\n",
       "      <td>24.0</td>\n",
       "      <td>6.523394e+08</td>\n",
       "      <td>1.301399e+09</td>\n",
       "      <td>20.296075</td>\n",
       "      <td>20.986706</td>\n",
       "      <td>-0.033333</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.039425</td>\n",
       "      <td>0.849080</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.118675</td>\n",
       "      <td>-0.067377</td>\n",
       "      <td>-0.053691</td>\n",
       "      <td>-0.041891</td>\n",
       "      <td>-0.030783</td>\n",
       "      <td>-0.018184</td>\n",
       "      <td>0.055164</td>\n",
       "      <td>0.175783</td>\n",
       "      <td>0.190067</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709878</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-08-31</td>\n",
       "      <td>13.56</td>\n",
       "      <td>24</td>\n",
       "      <td>23.0</td>\n",
       "      <td>7.955351e+09</td>\n",
       "      <td>1.054667e+10</td>\n",
       "      <td>22.797111</td>\n",
       "      <td>23.079076</td>\n",
       "      <td>-0.025862</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.027103</td>\n",
       "      <td>0.071030</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.127963</td>\n",
       "      <td>-0.101104</td>\n",
       "      <td>-0.081604</td>\n",
       "      <td>-0.067501</td>\n",
       "      <td>-0.053251</td>\n",
       "      <td>-0.037892</td>\n",
       "      <td>-0.019222</td>\n",
       "      <td>0.004010</td>\n",
       "      <td>0.046254</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709879</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-09-30</td>\n",
       "      <td>14.54</td>\n",
       "      <td>25</td>\n",
       "      <td>20.0</td>\n",
       "      <td>8.530295e+09</td>\n",
       "      <td>1.130889e+10</td>\n",
       "      <td>22.866890</td>\n",
       "      <td>23.148855</td>\n",
       "      <td>0.072271</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>0.071030</td>\n",
       "      <td>-0.048696</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.077841</td>\n",
       "      <td>-0.048326</td>\n",
       "      <td>-0.030102</td>\n",
       "      <td>-0.016111</td>\n",
       "      <td>-0.004367</td>\n",
       "      <td>0.005559</td>\n",
       "      <td>0.017018</td>\n",
       "      <td>0.033242</td>\n",
       "      <td>0.066314</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709880</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-10-31</td>\n",
       "      <td>13.85</td>\n",
       "      <td>26</td>\n",
       "      <td>17.0</td>\n",
       "      <td>8.125488e+09</td>\n",
       "      <td>1.077222e+10</td>\n",
       "      <td>22.818272</td>\n",
       "      <td>23.100237</td>\n",
       "      <td>-0.047455</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.048696</td>\n",
       "      <td>-0.027956</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.104815</td>\n",
       "      <td>-0.070334</td>\n",
       "      <td>-0.049764</td>\n",
       "      <td>-0.033905</td>\n",
       "      <td>-0.020315</td>\n",
       "      <td>-0.006363</td>\n",
       "      <td>0.010970</td>\n",
       "      <td>0.035557</td>\n",
       "      <td>0.078925</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709881</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-11-30</td>\n",
       "      <td>13.48</td>\n",
       "      <td>27</td>\n",
       "      <td>22.0</td>\n",
       "      <td>7.908417e+09</td>\n",
       "      <td>1.048444e+10</td>\n",
       "      <td>22.791193</td>\n",
       "      <td>23.073159</td>\n",
       "      <td>-0.026715</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.027956</td>\n",
       "      <td>0.103358</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.050131</td>\n",
       "      <td>-0.024692</td>\n",
       "      <td>-0.007101</td>\n",
       "      <td>0.006883</td>\n",
       "      <td>0.020630</td>\n",
       "      <td>0.034527</td>\n",
       "      <td>0.050795</td>\n",
       "      <td>0.075465</td>\n",
       "      <td>0.123638</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709882</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>14.89</td>\n",
       "      <td>28</td>\n",
       "      <td>21.0</td>\n",
       "      <td>8.735632e+09</td>\n",
       "      <td>1.158111e+10</td>\n",
       "      <td>22.890676</td>\n",
       "      <td>23.172641</td>\n",
       "      <td>0.104599</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>0.103358</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.096007</td>\n",
       "      <td>-0.070909</td>\n",
       "      <td>-0.055072</td>\n",
       "      <td>-0.042784</td>\n",
       "      <td>-0.030481</td>\n",
       "      <td>-0.019060</td>\n",
       "      <td>-0.003987</td>\n",
       "      <td>0.016061</td>\n",
       "      <td>0.058594</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>709883 rows × 23 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         Stkcd      month  price  Rank  Freq  floatingvalue    totalvalue  \\\n",
       "0       000001 1991-05-31  38.34     2  24.0   1.016010e+09  1.859497e+09   \n",
       "1       000001 1991-06-30  33.99     3  23.0   9.007350e+08  1.648521e+09   \n",
       "2       000001 1991-07-31  29.54     4  16.0   7.828100e+08  1.432695e+09   \n",
       "3       000001 1991-08-31  15.00     5  15.0   6.748338e+08  1.346275e+09   \n",
       "4       000001 1991-09-30  14.50     6  24.0   6.523394e+08  1.301399e+09   \n",
       "...        ...        ...    ...   ...   ...            ...           ...   \n",
       "709878  605599 2023-08-31  13.56    24  23.0   7.955351e+09  1.054667e+10   \n",
       "709879  605599 2023-09-30  14.54    25  20.0   8.530295e+09  1.130889e+10   \n",
       "709880  605599 2023-10-31  13.85    26  17.0   8.125488e+09  1.077222e+10   \n",
       "709881  605599 2023-11-30  13.48    27  22.0   7.908417e+09  1.048444e+10   \n",
       "709882  605599 2023-12-31  14.89    28  21.0   8.735632e+09  1.158111e+10   \n",
       "\n",
       "            sizef      sizet    Return   rfmonth       ret  next_ret  w  \\\n",
       "0       20.739149  21.343572 -0.122253  0.006092 -0.128345 -0.119551  1   \n",
       "1       20.618722  21.223144 -0.113459  0.006092 -0.119551 -0.137013  1   \n",
       "2       20.478401  21.082823 -0.130921  0.006092 -0.137013 -0.417680  1   \n",
       "3       20.329977  21.020607 -0.411588  0.006092 -0.417680 -0.039425  1   \n",
       "4       20.296075  20.986706 -0.033333  0.006092 -0.039425  0.849080  1   \n",
       "...           ...        ...       ...       ...       ...       ... ..   \n",
       "709878  22.797111  23.079076 -0.025862  0.001241 -0.027103  0.071030  1   \n",
       "709879  22.866890  23.148855  0.072271  0.001241  0.071030 -0.048696  1   \n",
       "709880  22.818272  23.100237 -0.047455  0.001241 -0.048696 -0.027956  1   \n",
       "709881  22.791193  23.073159 -0.026715  0.001241 -0.027956  0.103358  1   \n",
       "709882  22.890676  23.172641  0.104599  0.001241  0.103358       NaN  1   \n",
       "\n",
       "             one       two     three      four      five       six     seven  \\\n",
       "0      -0.129118 -0.128345 -0.120582 -0.036993 -0.031989 -0.006657  0.055289   \n",
       "1      -0.309901 -0.119551 -0.115097  0.166237  0.177858  0.184748  0.190006   \n",
       "2      -0.244184 -0.128701 -0.086966 -0.052277  0.007620  0.067451  0.149691   \n",
       "3      -0.161430 -0.110028 -0.049934 -0.014296  0.018298  0.060859  0.219168   \n",
       "4      -0.118675 -0.067377 -0.053691 -0.041891 -0.030783 -0.018184  0.055164   \n",
       "...          ...       ...       ...       ...       ...       ...       ...   \n",
       "709878 -0.127963 -0.101104 -0.081604 -0.067501 -0.053251 -0.037892 -0.019222   \n",
       "709879 -0.077841 -0.048326 -0.030102 -0.016111 -0.004367  0.005559  0.017018   \n",
       "709880 -0.104815 -0.070334 -0.049764 -0.033905 -0.020315 -0.006363  0.010970   \n",
       "709881 -0.050131 -0.024692 -0.007101  0.006883  0.020630  0.034527  0.050795   \n",
       "709882 -0.096007 -0.070909 -0.055072 -0.042784 -0.030481 -0.019060 -0.003987   \n",
       "\n",
       "           eight      nine  \n",
       "0       0.080639  0.202117  \n",
       "1       0.190283  0.201980  \n",
       "2       0.216426  0.246553  \n",
       "3       0.233226  0.238218  \n",
       "4       0.175783  0.190067  \n",
       "...          ...       ...  \n",
       "709878  0.004010  0.046254  \n",
       "709879  0.033242  0.066314  \n",
       "709880  0.035557  0.078925  \n",
       "709881  0.075465  0.123638  \n",
       "709882  0.016061  0.058594  \n",
       "\n",
       "[709883 rows x 23 columns]"
      ]
     },
     "execution_count": 183,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "portfolio=pd.merge(cross,fenweishu,on='month',how='left')\n",
    "portfolio"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 184,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Stkcd</th>\n",
       "      <th>month</th>\n",
       "      <th>price</th>\n",
       "      <th>Rank</th>\n",
       "      <th>Freq</th>\n",
       "      <th>floatingvalue</th>\n",
       "      <th>totalvalue</th>\n",
       "      <th>sizef</th>\n",
       "      <th>sizet</th>\n",
       "      <th>Return</th>\n",
       "      <th>rfmonth</th>\n",
       "      <th>ret</th>\n",
       "      <th>next_ret</th>\n",
       "      <th>w</th>\n",
       "      <th>one</th>\n",
       "      <th>two</th>\n",
       "      <th>three</th>\n",
       "      <th>four</th>\n",
       "      <th>five</th>\n",
       "      <th>six</th>\n",
       "      <th>seven</th>\n",
       "      <th>eight</th>\n",
       "      <th>nine</th>\n",
       "      <th>sort</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-05-31</td>\n",
       "      <td>38.34</td>\n",
       "      <td>2</td>\n",
       "      <td>24.0</td>\n",
       "      <td>1.016010e+09</td>\n",
       "      <td>1.859497e+09</td>\n",
       "      <td>20.739149</td>\n",
       "      <td>21.343572</td>\n",
       "      <td>-0.122253</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.128345</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.129118</td>\n",
       "      <td>-0.128345</td>\n",
       "      <td>-0.120582</td>\n",
       "      <td>-0.036993</td>\n",
       "      <td>-0.031989</td>\n",
       "      <td>-0.006657</td>\n",
       "      <td>0.055289</td>\n",
       "      <td>0.080639</td>\n",
       "      <td>0.202117</td>\n",
       "      <td>P2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-06-30</td>\n",
       "      <td>33.99</td>\n",
       "      <td>3</td>\n",
       "      <td>23.0</td>\n",
       "      <td>9.007350e+08</td>\n",
       "      <td>1.648521e+09</td>\n",
       "      <td>20.618722</td>\n",
       "      <td>21.223144</td>\n",
       "      <td>-0.113459</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>-0.137013</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.309901</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>-0.115097</td>\n",
       "      <td>0.166237</td>\n",
       "      <td>0.177858</td>\n",
       "      <td>0.184748</td>\n",
       "      <td>0.190006</td>\n",
       "      <td>0.190283</td>\n",
       "      <td>0.201980</td>\n",
       "      <td>P2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-07-31</td>\n",
       "      <td>29.54</td>\n",
       "      <td>4</td>\n",
       "      <td>16.0</td>\n",
       "      <td>7.828100e+08</td>\n",
       "      <td>1.432695e+09</td>\n",
       "      <td>20.478401</td>\n",
       "      <td>21.082823</td>\n",
       "      <td>-0.130921</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.137013</td>\n",
       "      <td>-0.417680</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.244184</td>\n",
       "      <td>-0.128701</td>\n",
       "      <td>-0.086966</td>\n",
       "      <td>-0.052277</td>\n",
       "      <td>0.007620</td>\n",
       "      <td>0.067451</td>\n",
       "      <td>0.149691</td>\n",
       "      <td>0.216426</td>\n",
       "      <td>0.246553</td>\n",
       "      <td>P2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-08-31</td>\n",
       "      <td>15.00</td>\n",
       "      <td>5</td>\n",
       "      <td>15.0</td>\n",
       "      <td>6.748338e+08</td>\n",
       "      <td>1.346275e+09</td>\n",
       "      <td>20.329977</td>\n",
       "      <td>21.020607</td>\n",
       "      <td>-0.411588</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.417680</td>\n",
       "      <td>-0.039425</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.161430</td>\n",
       "      <td>-0.110028</td>\n",
       "      <td>-0.049934</td>\n",
       "      <td>-0.014296</td>\n",
       "      <td>0.018298</td>\n",
       "      <td>0.060859</td>\n",
       "      <td>0.219168</td>\n",
       "      <td>0.233226</td>\n",
       "      <td>0.238218</td>\n",
       "      <td>P1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-09-30</td>\n",
       "      <td>14.50</td>\n",
       "      <td>6</td>\n",
       "      <td>24.0</td>\n",
       "      <td>6.523394e+08</td>\n",
       "      <td>1.301399e+09</td>\n",
       "      <td>20.296075</td>\n",
       "      <td>20.986706</td>\n",
       "      <td>-0.033333</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.039425</td>\n",
       "      <td>0.849080</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.118675</td>\n",
       "      <td>-0.067377</td>\n",
       "      <td>-0.053691</td>\n",
       "      <td>-0.041891</td>\n",
       "      <td>-0.030783</td>\n",
       "      <td>-0.018184</td>\n",
       "      <td>0.055164</td>\n",
       "      <td>0.175783</td>\n",
       "      <td>0.190067</td>\n",
       "      <td>P5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709878</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-08-31</td>\n",
       "      <td>13.56</td>\n",
       "      <td>24</td>\n",
       "      <td>23.0</td>\n",
       "      <td>7.955351e+09</td>\n",
       "      <td>1.054667e+10</td>\n",
       "      <td>22.797111</td>\n",
       "      <td>23.079076</td>\n",
       "      <td>-0.025862</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.027103</td>\n",
       "      <td>0.071030</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.127963</td>\n",
       "      <td>-0.101104</td>\n",
       "      <td>-0.081604</td>\n",
       "      <td>-0.067501</td>\n",
       "      <td>-0.053251</td>\n",
       "      <td>-0.037892</td>\n",
       "      <td>-0.019222</td>\n",
       "      <td>0.004010</td>\n",
       "      <td>0.046254</td>\n",
       "      <td>P7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709879</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-09-30</td>\n",
       "      <td>14.54</td>\n",
       "      <td>25</td>\n",
       "      <td>20.0</td>\n",
       "      <td>8.530295e+09</td>\n",
       "      <td>1.130889e+10</td>\n",
       "      <td>22.866890</td>\n",
       "      <td>23.148855</td>\n",
       "      <td>0.072271</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>0.071030</td>\n",
       "      <td>-0.048696</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.077841</td>\n",
       "      <td>-0.048326</td>\n",
       "      <td>-0.030102</td>\n",
       "      <td>-0.016111</td>\n",
       "      <td>-0.004367</td>\n",
       "      <td>0.005559</td>\n",
       "      <td>0.017018</td>\n",
       "      <td>0.033242</td>\n",
       "      <td>0.066314</td>\n",
       "      <td>Pmax</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709880</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-10-31</td>\n",
       "      <td>13.85</td>\n",
       "      <td>26</td>\n",
       "      <td>17.0</td>\n",
       "      <td>8.125488e+09</td>\n",
       "      <td>1.077222e+10</td>\n",
       "      <td>22.818272</td>\n",
       "      <td>23.100237</td>\n",
       "      <td>-0.047455</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.048696</td>\n",
       "      <td>-0.027956</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.104815</td>\n",
       "      <td>-0.070334</td>\n",
       "      <td>-0.049764</td>\n",
       "      <td>-0.033905</td>\n",
       "      <td>-0.020315</td>\n",
       "      <td>-0.006363</td>\n",
       "      <td>0.010970</td>\n",
       "      <td>0.035557</td>\n",
       "      <td>0.078925</td>\n",
       "      <td>P4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709881</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-11-30</td>\n",
       "      <td>13.48</td>\n",
       "      <td>27</td>\n",
       "      <td>22.0</td>\n",
       "      <td>7.908417e+09</td>\n",
       "      <td>1.048444e+10</td>\n",
       "      <td>22.791193</td>\n",
       "      <td>23.073159</td>\n",
       "      <td>-0.026715</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.027956</td>\n",
       "      <td>0.103358</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.050131</td>\n",
       "      <td>-0.024692</td>\n",
       "      <td>-0.007101</td>\n",
       "      <td>0.006883</td>\n",
       "      <td>0.020630</td>\n",
       "      <td>0.034527</td>\n",
       "      <td>0.050795</td>\n",
       "      <td>0.075465</td>\n",
       "      <td>0.123638</td>\n",
       "      <td>P2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709882</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>14.89</td>\n",
       "      <td>28</td>\n",
       "      <td>21.0</td>\n",
       "      <td>8.735632e+09</td>\n",
       "      <td>1.158111e+10</td>\n",
       "      <td>22.890676</td>\n",
       "      <td>23.172641</td>\n",
       "      <td>0.104599</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>0.103358</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.096007</td>\n",
       "      <td>-0.070909</td>\n",
       "      <td>-0.055072</td>\n",
       "      <td>-0.042784</td>\n",
       "      <td>-0.030481</td>\n",
       "      <td>-0.019060</td>\n",
       "      <td>-0.003987</td>\n",
       "      <td>0.016061</td>\n",
       "      <td>0.058594</td>\n",
       "      <td>Pmax</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>709883 rows × 24 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         Stkcd      month  price  Rank  Freq  floatingvalue    totalvalue  \\\n",
       "0       000001 1991-05-31  38.34     2  24.0   1.016010e+09  1.859497e+09   \n",
       "1       000001 1991-06-30  33.99     3  23.0   9.007350e+08  1.648521e+09   \n",
       "2       000001 1991-07-31  29.54     4  16.0   7.828100e+08  1.432695e+09   \n",
       "3       000001 1991-08-31  15.00     5  15.0   6.748338e+08  1.346275e+09   \n",
       "4       000001 1991-09-30  14.50     6  24.0   6.523394e+08  1.301399e+09   \n",
       "...        ...        ...    ...   ...   ...            ...           ...   \n",
       "709878  605599 2023-08-31  13.56    24  23.0   7.955351e+09  1.054667e+10   \n",
       "709879  605599 2023-09-30  14.54    25  20.0   8.530295e+09  1.130889e+10   \n",
       "709880  605599 2023-10-31  13.85    26  17.0   8.125488e+09  1.077222e+10   \n",
       "709881  605599 2023-11-30  13.48    27  22.0   7.908417e+09  1.048444e+10   \n",
       "709882  605599 2023-12-31  14.89    28  21.0   8.735632e+09  1.158111e+10   \n",
       "\n",
       "            sizef      sizet    Return   rfmonth       ret  next_ret  w  \\\n",
       "0       20.739149  21.343572 -0.122253  0.006092 -0.128345 -0.119551  1   \n",
       "1       20.618722  21.223144 -0.113459  0.006092 -0.119551 -0.137013  1   \n",
       "2       20.478401  21.082823 -0.130921  0.006092 -0.137013 -0.417680  1   \n",
       "3       20.329977  21.020607 -0.411588  0.006092 -0.417680 -0.039425  1   \n",
       "4       20.296075  20.986706 -0.033333  0.006092 -0.039425  0.849080  1   \n",
       "...           ...        ...       ...       ...       ...       ... ..   \n",
       "709878  22.797111  23.079076 -0.025862  0.001241 -0.027103  0.071030  1   \n",
       "709879  22.866890  23.148855  0.072271  0.001241  0.071030 -0.048696  1   \n",
       "709880  22.818272  23.100237 -0.047455  0.001241 -0.048696 -0.027956  1   \n",
       "709881  22.791193  23.073159 -0.026715  0.001241 -0.027956  0.103358  1   \n",
       "709882  22.890676  23.172641  0.104599  0.001241  0.103358       NaN  1   \n",
       "\n",
       "             one       two     three      four      five       six     seven  \\\n",
       "0      -0.129118 -0.128345 -0.120582 -0.036993 -0.031989 -0.006657  0.055289   \n",
       "1      -0.309901 -0.119551 -0.115097  0.166237  0.177858  0.184748  0.190006   \n",
       "2      -0.244184 -0.128701 -0.086966 -0.052277  0.007620  0.067451  0.149691   \n",
       "3      -0.161430 -0.110028 -0.049934 -0.014296  0.018298  0.060859  0.219168   \n",
       "4      -0.118675 -0.067377 -0.053691 -0.041891 -0.030783 -0.018184  0.055164   \n",
       "...          ...       ...       ...       ...       ...       ...       ...   \n",
       "709878 -0.127963 -0.101104 -0.081604 -0.067501 -0.053251 -0.037892 -0.019222   \n",
       "709879 -0.077841 -0.048326 -0.030102 -0.016111 -0.004367  0.005559  0.017018   \n",
       "709880 -0.104815 -0.070334 -0.049764 -0.033905 -0.020315 -0.006363  0.010970   \n",
       "709881 -0.050131 -0.024692 -0.007101  0.006883  0.020630  0.034527  0.050795   \n",
       "709882 -0.096007 -0.070909 -0.055072 -0.042784 -0.030481 -0.019060 -0.003987   \n",
       "\n",
       "           eight      nine  sort  \n",
       "0       0.080639  0.202117    P2  \n",
       "1       0.190283  0.201980    P2  \n",
       "2       0.216426  0.246553    P2  \n",
       "3       0.233226  0.238218    P1  \n",
       "4       0.175783  0.190067    P5  \n",
       "...          ...       ...   ...  \n",
       "709878  0.004010  0.046254    P7  \n",
       "709879  0.033242  0.066314  Pmax  \n",
       "709880  0.035557  0.078925    P4  \n",
       "709881  0.075465  0.123638    P2  \n",
       "709882  0.016061  0.058594  Pmax  \n",
       "\n",
       "[709883 rows x 24 columns]"
      ]
     },
     "execution_count": 184,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# where if else(if else)\n",
    "portfolio['sort'] = np.where(\n",
    "    portfolio['ret'] <= portfolio['one'], 'P1',\n",
    "    np.where(\n",
    "        portfolio['ret'] <= portfolio['two'], 'P2',\n",
    "        np.where(\n",
    "            portfolio['ret'] <= portfolio['three'], 'P3',\n",
    "            np.where(\n",
    "                portfolio['ret'] <= portfolio['four'], 'P4',\n",
    "                np.where(\n",
    "                    portfolio['ret'] <= portfolio['five'], 'P5',\n",
    "                    np.where(\n",
    "                        portfolio['ret'] <= portfolio['six'], 'P6',\n",
    "                        np.where(\n",
    "                            portfolio['ret'] <= portfolio['seven'], 'P7',\n",
    "                            np.where(\n",
    "                                portfolio['ret'] <= portfolio['eight'], 'P8',\n",
    "                                np.where(\n",
    "                                    portfolio['ret'] <= portfolio['nine'],\n",
    "                                    'P9', 'Pmax')))))))))\n",
    "portfolio\n",
    "# 把ret和后边几列比较"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 投资策略\n",
    "选择和收益率线性相关的变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 185,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Stkcd</th>\n",
       "      <th>month</th>\n",
       "      <th>price</th>\n",
       "      <th>Rank</th>\n",
       "      <th>Freq</th>\n",
       "      <th>floatingvalue</th>\n",
       "      <th>totalvalue</th>\n",
       "      <th>sizef</th>\n",
       "      <th>sizet</th>\n",
       "      <th>Return</th>\n",
       "      <th>rfmonth</th>\n",
       "      <th>ret</th>\n",
       "      <th>next_ret</th>\n",
       "      <th>w</th>\n",
       "      <th>one</th>\n",
       "      <th>two</th>\n",
       "      <th>three</th>\n",
       "      <th>four</th>\n",
       "      <th>five</th>\n",
       "      <th>six</th>\n",
       "      <th>seven</th>\n",
       "      <th>eight</th>\n",
       "      <th>nine</th>\n",
       "      <th>sort</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-05-31</td>\n",
       "      <td>38.34</td>\n",
       "      <td>2</td>\n",
       "      <td>24.0</td>\n",
       "      <td>1.016010e+09</td>\n",
       "      <td>1.859497e+09</td>\n",
       "      <td>20.739149</td>\n",
       "      <td>21.343572</td>\n",
       "      <td>-0.122253</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.128345</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.129118</td>\n",
       "      <td>-0.128345</td>\n",
       "      <td>-0.120582</td>\n",
       "      <td>-0.036993</td>\n",
       "      <td>-0.031989</td>\n",
       "      <td>-0.006657</td>\n",
       "      <td>0.055289</td>\n",
       "      <td>0.080639</td>\n",
       "      <td>0.202117</td>\n",
       "      <td>P2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-06-30</td>\n",
       "      <td>33.99</td>\n",
       "      <td>3</td>\n",
       "      <td>23.0</td>\n",
       "      <td>9.007350e+08</td>\n",
       "      <td>1.648521e+09</td>\n",
       "      <td>20.618722</td>\n",
       "      <td>21.223144</td>\n",
       "      <td>-0.113459</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>-0.137013</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.309901</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>-0.115097</td>\n",
       "      <td>0.166237</td>\n",
       "      <td>0.177858</td>\n",
       "      <td>0.184748</td>\n",
       "      <td>0.190006</td>\n",
       "      <td>0.190283</td>\n",
       "      <td>0.201980</td>\n",
       "      <td>P2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-07-31</td>\n",
       "      <td>29.54</td>\n",
       "      <td>4</td>\n",
       "      <td>16.0</td>\n",
       "      <td>7.828100e+08</td>\n",
       "      <td>1.432695e+09</td>\n",
       "      <td>20.478401</td>\n",
       "      <td>21.082823</td>\n",
       "      <td>-0.130921</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.137013</td>\n",
       "      <td>-0.417680</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.244184</td>\n",
       "      <td>-0.128701</td>\n",
       "      <td>-0.086966</td>\n",
       "      <td>-0.052277</td>\n",
       "      <td>0.007620</td>\n",
       "      <td>0.067451</td>\n",
       "      <td>0.149691</td>\n",
       "      <td>0.216426</td>\n",
       "      <td>0.246553</td>\n",
       "      <td>P2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-08-31</td>\n",
       "      <td>15.00</td>\n",
       "      <td>5</td>\n",
       "      <td>15.0</td>\n",
       "      <td>6.748338e+08</td>\n",
       "      <td>1.346275e+09</td>\n",
       "      <td>20.329977</td>\n",
       "      <td>21.020607</td>\n",
       "      <td>-0.411588</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.417680</td>\n",
       "      <td>-0.039425</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.161430</td>\n",
       "      <td>-0.110028</td>\n",
       "      <td>-0.049934</td>\n",
       "      <td>-0.014296</td>\n",
       "      <td>0.018298</td>\n",
       "      <td>0.060859</td>\n",
       "      <td>0.219168</td>\n",
       "      <td>0.233226</td>\n",
       "      <td>0.238218</td>\n",
       "      <td>P1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>000001</td>\n",
       "      <td>1991-09-30</td>\n",
       "      <td>14.50</td>\n",
       "      <td>6</td>\n",
       "      <td>24.0</td>\n",
       "      <td>6.523394e+08</td>\n",
       "      <td>1.301399e+09</td>\n",
       "      <td>20.296075</td>\n",
       "      <td>20.986706</td>\n",
       "      <td>-0.033333</td>\n",
       "      <td>0.006092</td>\n",
       "      <td>-0.039425</td>\n",
       "      <td>0.849080</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.118675</td>\n",
       "      <td>-0.067377</td>\n",
       "      <td>-0.053691</td>\n",
       "      <td>-0.041891</td>\n",
       "      <td>-0.030783</td>\n",
       "      <td>-0.018184</td>\n",
       "      <td>0.055164</td>\n",
       "      <td>0.175783</td>\n",
       "      <td>0.190067</td>\n",
       "      <td>P5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709877</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-07-31</td>\n",
       "      <td>13.92</td>\n",
       "      <td>23</td>\n",
       "      <td>21.0</td>\n",
       "      <td>8.166555e+09</td>\n",
       "      <td>1.082667e+10</td>\n",
       "      <td>22.823313</td>\n",
       "      <td>23.105278</td>\n",
       "      <td>0.053747</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>0.052506</td>\n",
       "      <td>-0.027103</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.109131</td>\n",
       "      <td>-0.061730</td>\n",
       "      <td>-0.031833</td>\n",
       "      <td>-0.004677</td>\n",
       "      <td>0.018420</td>\n",
       "      <td>0.038359</td>\n",
       "      <td>0.058412</td>\n",
       "      <td>0.084426</td>\n",
       "      <td>0.130416</td>\n",
       "      <td>P7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709878</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-08-31</td>\n",
       "      <td>13.56</td>\n",
       "      <td>24</td>\n",
       "      <td>23.0</td>\n",
       "      <td>7.955351e+09</td>\n",
       "      <td>1.054667e+10</td>\n",
       "      <td>22.797111</td>\n",
       "      <td>23.079076</td>\n",
       "      <td>-0.025862</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.027103</td>\n",
       "      <td>0.071030</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.127963</td>\n",
       "      <td>-0.101104</td>\n",
       "      <td>-0.081604</td>\n",
       "      <td>-0.067501</td>\n",
       "      <td>-0.053251</td>\n",
       "      <td>-0.037892</td>\n",
       "      <td>-0.019222</td>\n",
       "      <td>0.004010</td>\n",
       "      <td>0.046254</td>\n",
       "      <td>P7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709879</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-09-30</td>\n",
       "      <td>14.54</td>\n",
       "      <td>25</td>\n",
       "      <td>20.0</td>\n",
       "      <td>8.530295e+09</td>\n",
       "      <td>1.130889e+10</td>\n",
       "      <td>22.866890</td>\n",
       "      <td>23.148855</td>\n",
       "      <td>0.072271</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>0.071030</td>\n",
       "      <td>-0.048696</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.077841</td>\n",
       "      <td>-0.048326</td>\n",
       "      <td>-0.030102</td>\n",
       "      <td>-0.016111</td>\n",
       "      <td>-0.004367</td>\n",
       "      <td>0.005559</td>\n",
       "      <td>0.017018</td>\n",
       "      <td>0.033242</td>\n",
       "      <td>0.066314</td>\n",
       "      <td>Pmax</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709880</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-10-31</td>\n",
       "      <td>13.85</td>\n",
       "      <td>26</td>\n",
       "      <td>17.0</td>\n",
       "      <td>8.125488e+09</td>\n",
       "      <td>1.077222e+10</td>\n",
       "      <td>22.818272</td>\n",
       "      <td>23.100237</td>\n",
       "      <td>-0.047455</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.048696</td>\n",
       "      <td>-0.027956</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.104815</td>\n",
       "      <td>-0.070334</td>\n",
       "      <td>-0.049764</td>\n",
       "      <td>-0.033905</td>\n",
       "      <td>-0.020315</td>\n",
       "      <td>-0.006363</td>\n",
       "      <td>0.010970</td>\n",
       "      <td>0.035557</td>\n",
       "      <td>0.078925</td>\n",
       "      <td>P4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>709881</th>\n",
       "      <td>605599</td>\n",
       "      <td>2023-11-30</td>\n",
       "      <td>13.48</td>\n",
       "      <td>27</td>\n",
       "      <td>22.0</td>\n",
       "      <td>7.908417e+09</td>\n",
       "      <td>1.048444e+10</td>\n",
       "      <td>22.791193</td>\n",
       "      <td>23.073159</td>\n",
       "      <td>-0.026715</td>\n",
       "      <td>0.001241</td>\n",
       "      <td>-0.027956</td>\n",
       "      <td>0.103358</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.050131</td>\n",
       "      <td>-0.024692</td>\n",
       "      <td>-0.007101</td>\n",
       "      <td>0.006883</td>\n",
       "      <td>0.020630</td>\n",
       "      <td>0.034527</td>\n",
       "      <td>0.050795</td>\n",
       "      <td>0.075465</td>\n",
       "      <td>0.123638</td>\n",
       "      <td>P2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>700739 rows × 24 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         Stkcd      month  price  Rank  Freq  floatingvalue    totalvalue  \\\n",
       "0       000001 1991-05-31  38.34     2  24.0   1.016010e+09  1.859497e+09   \n",
       "1       000001 1991-06-30  33.99     3  23.0   9.007350e+08  1.648521e+09   \n",
       "2       000001 1991-07-31  29.54     4  16.0   7.828100e+08  1.432695e+09   \n",
       "3       000001 1991-08-31  15.00     5  15.0   6.748338e+08  1.346275e+09   \n",
       "4       000001 1991-09-30  14.50     6  24.0   6.523394e+08  1.301399e+09   \n",
       "...        ...        ...    ...   ...   ...            ...           ...   \n",
       "709877  605599 2023-07-31  13.92    23  21.0   8.166555e+09  1.082667e+10   \n",
       "709878  605599 2023-08-31  13.56    24  23.0   7.955351e+09  1.054667e+10   \n",
       "709879  605599 2023-09-30  14.54    25  20.0   8.530295e+09  1.130889e+10   \n",
       "709880  605599 2023-10-31  13.85    26  17.0   8.125488e+09  1.077222e+10   \n",
       "709881  605599 2023-11-30  13.48    27  22.0   7.908417e+09  1.048444e+10   \n",
       "\n",
       "            sizef      sizet    Return   rfmonth       ret  next_ret  w  \\\n",
       "0       20.739149  21.343572 -0.122253  0.006092 -0.128345 -0.119551  1   \n",
       "1       20.618722  21.223144 -0.113459  0.006092 -0.119551 -0.137013  1   \n",
       "2       20.478401  21.082823 -0.130921  0.006092 -0.137013 -0.417680  1   \n",
       "3       20.329977  21.020607 -0.411588  0.006092 -0.417680 -0.039425  1   \n",
       "4       20.296075  20.986706 -0.033333  0.006092 -0.039425  0.849080  1   \n",
       "...           ...        ...       ...       ...       ...       ... ..   \n",
       "709877  22.823313  23.105278  0.053747  0.001241  0.052506 -0.027103  1   \n",
       "709878  22.797111  23.079076 -0.025862  0.001241 -0.027103  0.071030  1   \n",
       "709879  22.866890  23.148855  0.072271  0.001241  0.071030 -0.048696  1   \n",
       "709880  22.818272  23.100237 -0.047455  0.001241 -0.048696 -0.027956  1   \n",
       "709881  22.791193  23.073159 -0.026715  0.001241 -0.027956  0.103358  1   \n",
       "\n",
       "             one       two     three      four      five       six     seven  \\\n",
       "0      -0.129118 -0.128345 -0.120582 -0.036993 -0.031989 -0.006657  0.055289   \n",
       "1      -0.309901 -0.119551 -0.115097  0.166237  0.177858  0.184748  0.190006   \n",
       "2      -0.244184 -0.128701 -0.086966 -0.052277  0.007620  0.067451  0.149691   \n",
       "3      -0.161430 -0.110028 -0.049934 -0.014296  0.018298  0.060859  0.219168   \n",
       "4      -0.118675 -0.067377 -0.053691 -0.041891 -0.030783 -0.018184  0.055164   \n",
       "...          ...       ...       ...       ...       ...       ...       ...   \n",
       "709877 -0.109131 -0.061730 -0.031833 -0.004677  0.018420  0.038359  0.058412   \n",
       "709878 -0.127963 -0.101104 -0.081604 -0.067501 -0.053251 -0.037892 -0.019222   \n",
       "709879 -0.077841 -0.048326 -0.030102 -0.016111 -0.004367  0.005559  0.017018   \n",
       "709880 -0.104815 -0.070334 -0.049764 -0.033905 -0.020315 -0.006363  0.010970   \n",
       "709881 -0.050131 -0.024692 -0.007101  0.006883  0.020630  0.034527  0.050795   \n",
       "\n",
       "           eight      nine  sort  \n",
       "0       0.080639  0.202117    P2  \n",
       "1       0.190283  0.201980    P2  \n",
       "2       0.216426  0.246553    P2  \n",
       "3       0.233226  0.238218    P1  \n",
       "4       0.175783  0.190067    P5  \n",
       "...          ...       ...   ...  \n",
       "709877  0.084426  0.130416    P7  \n",
       "709878  0.004010  0.046254    P7  \n",
       "709879  0.033242  0.066314  Pmax  \n",
       "709880  0.035557  0.078925    P4  \n",
       "709881  0.075465  0.123638    P2  \n",
       "\n",
       "[700739 rows x 24 columns]"
      ]
     },
     "execution_count": 185,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "portfolio=portfolio.dropna(subset=['next_ret','floatingvalue'])\n",
    "portfolio"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 186,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th>sort</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">1991-01-31</th>\n",
       "      <th>P1</th>\n",
       "      <td>-0.041567</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P2</th>\n",
       "      <td>0.010496</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P4</th>\n",
       "      <td>0.038284</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P6</th>\n",
       "      <td>0.081305</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P8</th>\n",
       "      <td>0.028134</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">2023-11-30</th>\n",
       "      <th>P6</th>\n",
       "      <td>-0.012190</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P7</th>\n",
       "      <td>-0.023572</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P8</th>\n",
       "      <td>-0.026295</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P9</th>\n",
       "      <td>0.005428</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Pmax</th>\n",
       "      <td>-0.050056</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3946 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                        0\n",
       "month      sort          \n",
       "1991-01-31 P1   -0.041567\n",
       "           P2    0.010496\n",
       "           P4    0.038284\n",
       "           P6    0.081305\n",
       "           P8    0.028134\n",
       "...                   ...\n",
       "2023-11-30 P6   -0.012190\n",
       "           P7   -0.023572\n",
       "           P8   -0.026295\n",
       "           P9    0.005428\n",
       "           Pmax -0.050056\n",
       "\n",
       "[3946 rows x 1 columns]"
      ]
     },
     "execution_count": 186,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 短期动量策略\n",
    "portfolio_mom=pd.DataFrame(portfolio.groupby(['month','sort']).apply(\n",
    "    lambda x: np.average(x['next_ret'],weights=x['floatingvalue']),\n",
    "include_groups=False))\n",
    "portfolio_mom"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 187,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>month</th>\n",
       "      <th>sort</th>\n",
       "      <th>p</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1991-02-28</td>\n",
       "      <td>P1</td>\n",
       "      <td>-0.041567</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1991-02-28</td>\n",
       "      <td>P2</td>\n",
       "      <td>0.010496</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1991-02-28</td>\n",
       "      <td>P4</td>\n",
       "      <td>0.038284</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1991-02-28</td>\n",
       "      <td>P6</td>\n",
       "      <td>0.081305</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1991-02-28</td>\n",
       "      <td>P8</td>\n",
       "      <td>0.028134</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3941</th>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>P6</td>\n",
       "      <td>-0.012190</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3942</th>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>P7</td>\n",
       "      <td>-0.023572</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3943</th>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>P8</td>\n",
       "      <td>-0.026295</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3944</th>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>P9</td>\n",
       "      <td>0.005428</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3945</th>\n",
       "      <td>2023-12-31</td>\n",
       "      <td>Pmax</td>\n",
       "      <td>-0.050056</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3946 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          month  sort         p\n",
       "0    1991-02-28    P1 -0.041567\n",
       "1    1991-02-28    P2  0.010496\n",
       "2    1991-02-28    P4  0.038284\n",
       "3    1991-02-28    P6  0.081305\n",
       "4    1991-02-28    P8  0.028134\n",
       "...         ...   ...       ...\n",
       "3941 2023-12-31    P6 -0.012190\n",
       "3942 2023-12-31    P7 -0.023572\n",
       "3943 2023-12-31    P8 -0.026295\n",
       "3944 2023-12-31    P9  0.005428\n",
       "3945 2023-12-31  Pmax -0.050056\n",
       "\n",
       "[3946 rows x 3 columns]"
      ]
     },
     "execution_count": 187,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "portfolio_mom=portfolio_mom.reset_index()\n",
    "portfolio_mom.columns=['month','sort','p']\n",
    "portfolio_mom['month']=portfolio_mom['month']+MonthEnd(1)\n",
    "portfolio_mom.dropna(subset=['p'],inplace=True)\n",
    "portfolio_mom"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 188,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>sort</th>\n",
       "      <th>P1</th>\n",
       "      <th>P2</th>\n",
       "      <th>P3</th>\n",
       "      <th>P4</th>\n",
       "      <th>P5</th>\n",
       "      <th>P6</th>\n",
       "      <th>P7</th>\n",
       "      <th>P8</th>\n",
       "      <th>P9</th>\n",
       "      <th>Pmax</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1991-02-28</th>\n",
       "      <td>-0.041567</td>\n",
       "      <td>0.010496</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.038284</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.081305</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.028134</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.002070</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-03-31</th>\n",
       "      <td>-0.133253</td>\n",
       "      <td>-0.069140</td>\n",
       "      <td>-0.133293</td>\n",
       "      <td>0.023904</td>\n",
       "      <td>-0.125264</td>\n",
       "      <td>0.070941</td>\n",
       "      <td>-0.133504</td>\n",
       "      <td>-0.044343</td>\n",
       "      <td>-0.070455</td>\n",
       "      <td>-0.059149</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-04-30</th>\n",
       "      <td>-0.122736</td>\n",
       "      <td>-0.123391</td>\n",
       "      <td>-0.103582</td>\n",
       "      <td>-0.077512</td>\n",
       "      <td>-0.133193</td>\n",
       "      <td>-0.000595</td>\n",
       "      <td>0.070484</td>\n",
       "      <td>-0.097744</td>\n",
       "      <td>0.120035</td>\n",
       "      <td>0.087227</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-05-31</th>\n",
       "      <td>-0.006657</td>\n",
       "      <td>-0.129118</td>\n",
       "      <td>-0.036993</td>\n",
       "      <td>-0.120582</td>\n",
       "      <td>-0.130814</td>\n",
       "      <td>-0.031989</td>\n",
       "      <td>0.080639</td>\n",
       "      <td>0.055289</td>\n",
       "      <td>0.202117</td>\n",
       "      <td>0.238572</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-06-30</th>\n",
       "      <td>-0.093032</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>-0.460637</td>\n",
       "      <td>-0.309901</td>\n",
       "      <td>0.190006</td>\n",
       "      <td>0.177858</td>\n",
       "      <td>0.213185</td>\n",
       "      <td>0.190283</td>\n",
       "      <td>0.166237</td>\n",
       "      <td>0.201980</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-08-31</th>\n",
       "      <td>-0.048515</td>\n",
       "      <td>-0.047374</td>\n",
       "      <td>-0.049198</td>\n",
       "      <td>-0.064861</td>\n",
       "      <td>-0.052590</td>\n",
       "      <td>-0.056458</td>\n",
       "      <td>-0.054358</td>\n",
       "      <td>-0.052533</td>\n",
       "      <td>-0.059833</td>\n",
       "      <td>-0.069041</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-09-30</th>\n",
       "      <td>-0.013215</td>\n",
       "      <td>-0.008910</td>\n",
       "      <td>-0.008950</td>\n",
       "      <td>0.000798</td>\n",
       "      <td>0.000158</td>\n",
       "      <td>0.002106</td>\n",
       "      <td>0.001202</td>\n",
       "      <td>-0.024952</td>\n",
       "      <td>-0.007080</td>\n",
       "      <td>-0.012874</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-10-31</th>\n",
       "      <td>-0.068257</td>\n",
       "      <td>-0.026400</td>\n",
       "      <td>-0.026712</td>\n",
       "      <td>-0.035206</td>\n",
       "      <td>-0.022298</td>\n",
       "      <td>-0.013751</td>\n",
       "      <td>-0.022298</td>\n",
       "      <td>-0.033380</td>\n",
       "      <td>-0.029932</td>\n",
       "      <td>0.008262</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-11-30</th>\n",
       "      <td>0.005351</td>\n",
       "      <td>-0.021096</td>\n",
       "      <td>0.009551</td>\n",
       "      <td>-0.004467</td>\n",
       "      <td>0.005741</td>\n",
       "      <td>0.011742</td>\n",
       "      <td>-0.004673</td>\n",
       "      <td>-0.001100</td>\n",
       "      <td>0.010682</td>\n",
       "      <td>0.005062</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-31</th>\n",
       "      <td>-0.023762</td>\n",
       "      <td>-0.023652</td>\n",
       "      <td>-0.021338</td>\n",
       "      <td>-0.023467</td>\n",
       "      <td>-0.014802</td>\n",
       "      <td>-0.012190</td>\n",
       "      <td>-0.023572</td>\n",
       "      <td>-0.026295</td>\n",
       "      <td>0.005428</td>\n",
       "      <td>-0.050056</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>395 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "sort              P1        P2        P3        P4        P5        P6  \\\n",
       "month                                                                    \n",
       "1991-02-28 -0.041567  0.010496       NaN  0.038284       NaN  0.081305   \n",
       "1991-03-31 -0.133253 -0.069140 -0.133293  0.023904 -0.125264  0.070941   \n",
       "1991-04-30 -0.122736 -0.123391 -0.103582 -0.077512 -0.133193 -0.000595   \n",
       "1991-05-31 -0.006657 -0.129118 -0.036993 -0.120582 -0.130814 -0.031989   \n",
       "1991-06-30 -0.093032 -0.119551 -0.460637 -0.309901  0.190006  0.177858   \n",
       "...              ...       ...       ...       ...       ...       ...   \n",
       "2023-08-31 -0.048515 -0.047374 -0.049198 -0.064861 -0.052590 -0.056458   \n",
       "2023-09-30 -0.013215 -0.008910 -0.008950  0.000798  0.000158  0.002106   \n",
       "2023-10-31 -0.068257 -0.026400 -0.026712 -0.035206 -0.022298 -0.013751   \n",
       "2023-11-30  0.005351 -0.021096  0.009551 -0.004467  0.005741  0.011742   \n",
       "2023-12-31 -0.023762 -0.023652 -0.021338 -0.023467 -0.014802 -0.012190   \n",
       "\n",
       "sort              P7        P8        P9      Pmax  \n",
       "month                                               \n",
       "1991-02-28       NaN  0.028134       NaN -0.002070  \n",
       "1991-03-31 -0.133504 -0.044343 -0.070455 -0.059149  \n",
       "1991-04-30  0.070484 -0.097744  0.120035  0.087227  \n",
       "1991-05-31  0.080639  0.055289  0.202117  0.238572  \n",
       "1991-06-30  0.213185  0.190283  0.166237  0.201980  \n",
       "...              ...       ...       ...       ...  \n",
       "2023-08-31 -0.054358 -0.052533 -0.059833 -0.069041  \n",
       "2023-09-30  0.001202 -0.024952 -0.007080 -0.012874  \n",
       "2023-10-31 -0.022298 -0.033380 -0.029932  0.008262  \n",
       "2023-11-30 -0.004673 -0.001100  0.010682  0.005062  \n",
       "2023-12-31 -0.023572 -0.026295  0.005428 -0.050056  \n",
       "\n",
       "[395 rows x 10 columns]"
      ]
     },
     "execution_count": 188,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "portfolio_mom=portfolio_mom.pivot(index='month',columns='sort',values='p')\n",
    "portfolio_mom"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 我的投资策略"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 189,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>sort</th>\n",
       "      <th>P1</th>\n",
       "      <th>P2</th>\n",
       "      <th>P3</th>\n",
       "      <th>P4</th>\n",
       "      <th>P5</th>\n",
       "      <th>P6</th>\n",
       "      <th>P7</th>\n",
       "      <th>P8</th>\n",
       "      <th>P9</th>\n",
       "      <th>Pmax</th>\n",
       "      <th>My_portfolio</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1991-02-28</th>\n",
       "      <td>-0.041567</td>\n",
       "      <td>0.010496</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.038284</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.081305</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.028134</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-0.002070</td>\n",
       "      <td>-0.039497</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-03-31</th>\n",
       "      <td>-0.133253</td>\n",
       "      <td>-0.069140</td>\n",
       "      <td>-0.133293</td>\n",
       "      <td>0.023904</td>\n",
       "      <td>-0.125264</td>\n",
       "      <td>0.070941</td>\n",
       "      <td>-0.133504</td>\n",
       "      <td>-0.044343</td>\n",
       "      <td>-0.070455</td>\n",
       "      <td>-0.059149</td>\n",
       "      <td>-0.074104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-04-30</th>\n",
       "      <td>-0.122736</td>\n",
       "      <td>-0.123391</td>\n",
       "      <td>-0.103582</td>\n",
       "      <td>-0.077512</td>\n",
       "      <td>-0.133193</td>\n",
       "      <td>-0.000595</td>\n",
       "      <td>0.070484</td>\n",
       "      <td>-0.097744</td>\n",
       "      <td>0.120035</td>\n",
       "      <td>0.087227</td>\n",
       "      <td>-0.209963</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-05-31</th>\n",
       "      <td>-0.006657</td>\n",
       "      <td>-0.129118</td>\n",
       "      <td>-0.036993</td>\n",
       "      <td>-0.120582</td>\n",
       "      <td>-0.130814</td>\n",
       "      <td>-0.031989</td>\n",
       "      <td>0.080639</td>\n",
       "      <td>0.055289</td>\n",
       "      <td>0.202117</td>\n",
       "      <td>0.238572</td>\n",
       "      <td>-0.245229</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1991-06-30</th>\n",
       "      <td>-0.093032</td>\n",
       "      <td>-0.119551</td>\n",
       "      <td>-0.460637</td>\n",
       "      <td>-0.309901</td>\n",
       "      <td>0.190006</td>\n",
       "      <td>0.177858</td>\n",
       "      <td>0.213185</td>\n",
       "      <td>0.190283</td>\n",
       "      <td>0.166237</td>\n",
       "      <td>0.201980</td>\n",
       "      <td>-0.295012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-08-31</th>\n",
       "      <td>-0.048515</td>\n",
       "      <td>-0.047374</td>\n",
       "      <td>-0.049198</td>\n",
       "      <td>-0.064861</td>\n",
       "      <td>-0.052590</td>\n",
       "      <td>-0.056458</td>\n",
       "      <td>-0.054358</td>\n",
       "      <td>-0.052533</td>\n",
       "      <td>-0.059833</td>\n",
       "      <td>-0.069041</td>\n",
       "      <td>0.020526</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-09-30</th>\n",
       "      <td>-0.013215</td>\n",
       "      <td>-0.008910</td>\n",
       "      <td>-0.008950</td>\n",
       "      <td>0.000798</td>\n",
       "      <td>0.000158</td>\n",
       "      <td>0.002106</td>\n",
       "      <td>0.001202</td>\n",
       "      <td>-0.024952</td>\n",
       "      <td>-0.007080</td>\n",
       "      <td>-0.012874</td>\n",
       "      <td>-0.000340</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-10-31</th>\n",
       "      <td>-0.068257</td>\n",
       "      <td>-0.026400</td>\n",
       "      <td>-0.026712</td>\n",
       "      <td>-0.035206</td>\n",
       "      <td>-0.022298</td>\n",
       "      <td>-0.013751</td>\n",
       "      <td>-0.022298</td>\n",
       "      <td>-0.033380</td>\n",
       "      <td>-0.029932</td>\n",
       "      <td>0.008262</td>\n",
       "      <td>-0.076519</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-11-30</th>\n",
       "      <td>0.005351</td>\n",
       "      <td>-0.021096</td>\n",
       "      <td>0.009551</td>\n",
       "      <td>-0.004467</td>\n",
       "      <td>0.005741</td>\n",
       "      <td>0.011742</td>\n",
       "      <td>-0.004673</td>\n",
       "      <td>-0.001100</td>\n",
       "      <td>0.010682</td>\n",
       "      <td>0.005062</td>\n",
       "      <td>0.000289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-31</th>\n",
       "      <td>-0.023762</td>\n",
       "      <td>-0.023652</td>\n",
       "      <td>-0.021338</td>\n",
       "      <td>-0.023467</td>\n",
       "      <td>-0.014802</td>\n",
       "      <td>-0.012190</td>\n",
       "      <td>-0.023572</td>\n",
       "      <td>-0.026295</td>\n",
       "      <td>0.005428</td>\n",
       "      <td>-0.050056</td>\n",
       "      <td>0.026293</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>395 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "sort              P1        P2        P3        P4        P5        P6  \\\n",
       "month                                                                    \n",
       "1991-02-28 -0.041567  0.010496       NaN  0.038284       NaN  0.081305   \n",
       "1991-03-31 -0.133253 -0.069140 -0.133293  0.023904 -0.125264  0.070941   \n",
       "1991-04-30 -0.122736 -0.123391 -0.103582 -0.077512 -0.133193 -0.000595   \n",
       "1991-05-31 -0.006657 -0.129118 -0.036993 -0.120582 -0.130814 -0.031989   \n",
       "1991-06-30 -0.093032 -0.119551 -0.460637 -0.309901  0.190006  0.177858   \n",
       "...              ...       ...       ...       ...       ...       ...   \n",
       "2023-08-31 -0.048515 -0.047374 -0.049198 -0.064861 -0.052590 -0.056458   \n",
       "2023-09-30 -0.013215 -0.008910 -0.008950  0.000798  0.000158  0.002106   \n",
       "2023-10-31 -0.068257 -0.026400 -0.026712 -0.035206 -0.022298 -0.013751   \n",
       "2023-11-30  0.005351 -0.021096  0.009551 -0.004467  0.005741  0.011742   \n",
       "2023-12-31 -0.023762 -0.023652 -0.021338 -0.023467 -0.014802 -0.012190   \n",
       "\n",
       "sort              P7        P8        P9      Pmax  My_portfolio  \n",
       "month                                                             \n",
       "1991-02-28       NaN  0.028134       NaN -0.002070     -0.039497  \n",
       "1991-03-31 -0.133504 -0.044343 -0.070455 -0.059149     -0.074104  \n",
       "1991-04-30  0.070484 -0.097744  0.120035  0.087227     -0.209963  \n",
       "1991-05-31  0.080639  0.055289  0.202117  0.238572     -0.245229  \n",
       "1991-06-30  0.213185  0.190283  0.166237  0.201980     -0.295012  \n",
       "...              ...       ...       ...       ...           ...  \n",
       "2023-08-31 -0.054358 -0.052533 -0.059833 -0.069041      0.020526  \n",
       "2023-09-30  0.001202 -0.024952 -0.007080 -0.012874     -0.000340  \n",
       "2023-10-31 -0.022298 -0.033380 -0.029932  0.008262     -0.076519  \n",
       "2023-11-30 -0.004673 -0.001100  0.010682  0.005062      0.000289  \n",
       "2023-12-31 -0.023572 -0.026295  0.005428 -0.050056      0.026293  \n",
       "\n",
       "[395 rows x 11 columns]"
      ]
     },
     "execution_count": 189,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "portfolio_mom['My_portfolio']=portfolio_mom['P1']-portfolio_mom['Pmax']\n",
    "portfolio_mom"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 190,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>sort</th>\n",
       "      <th>P1</th>\n",
       "      <th>P2</th>\n",
       "      <th>P3</th>\n",
       "      <th>P4</th>\n",
       "      <th>P5</th>\n",
       "      <th>P6</th>\n",
       "      <th>P7</th>\n",
       "      <th>P8</th>\n",
       "      <th>P9</th>\n",
       "      <th>Pmax</th>\n",
       "      <th>My_portfolio</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2000-01-31</th>\n",
       "      <td>0.128892</td>\n",
       "      <td>0.125095</td>\n",
       "      <td>0.109649</td>\n",
       "      <td>0.164682</td>\n",
       "      <td>0.134155</td>\n",
       "      <td>0.117154</td>\n",
       "      <td>0.154231</td>\n",
       "      <td>0.133388</td>\n",
       "      <td>0.189671</td>\n",
       "      <td>0.277708</td>\n",
       "      <td>-0.148816</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-02-29</th>\n",
       "      <td>0.148460</td>\n",
       "      <td>0.098851</td>\n",
       "      <td>0.122838</td>\n",
       "      <td>0.084378</td>\n",
       "      <td>0.193957</td>\n",
       "      <td>0.095636</td>\n",
       "      <td>0.080466</td>\n",
       "      <td>0.102473</td>\n",
       "      <td>0.169644</td>\n",
       "      <td>0.125983</td>\n",
       "      <td>0.022476</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-03-31</th>\n",
       "      <td>0.028538</td>\n",
       "      <td>0.056167</td>\n",
       "      <td>0.088460</td>\n",
       "      <td>0.093958</td>\n",
       "      <td>0.115092</td>\n",
       "      <td>0.082248</td>\n",
       "      <td>0.079722</td>\n",
       "      <td>0.081513</td>\n",
       "      <td>0.040770</td>\n",
       "      <td>-0.044828</td>\n",
       "      <td>0.073366</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-04-30</th>\n",
       "      <td>-0.005793</td>\n",
       "      <td>0.018555</td>\n",
       "      <td>0.037055</td>\n",
       "      <td>0.023933</td>\n",
       "      <td>0.009921</td>\n",
       "      <td>0.018328</td>\n",
       "      <td>0.021396</td>\n",
       "      <td>0.004873</td>\n",
       "      <td>-0.011356</td>\n",
       "      <td>-0.015714</td>\n",
       "      <td>0.009921</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-05-31</th>\n",
       "      <td>0.019856</td>\n",
       "      <td>0.013618</td>\n",
       "      <td>0.007191</td>\n",
       "      <td>0.016574</td>\n",
       "      <td>0.034658</td>\n",
       "      <td>0.026428</td>\n",
       "      <td>0.025010</td>\n",
       "      <td>0.058083</td>\n",
       "      <td>0.021637</td>\n",
       "      <td>0.036778</td>\n",
       "      <td>-0.016922</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-08-31</th>\n",
       "      <td>-0.048515</td>\n",
       "      <td>-0.047374</td>\n",
       "      <td>-0.049198</td>\n",
       "      <td>-0.064861</td>\n",
       "      <td>-0.052590</td>\n",
       "      <td>-0.056458</td>\n",
       "      <td>-0.054358</td>\n",
       "      <td>-0.052533</td>\n",
       "      <td>-0.059833</td>\n",
       "      <td>-0.069041</td>\n",
       "      <td>0.020526</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-09-30</th>\n",
       "      <td>-0.013215</td>\n",
       "      <td>-0.008910</td>\n",
       "      <td>-0.008950</td>\n",
       "      <td>0.000798</td>\n",
       "      <td>0.000158</td>\n",
       "      <td>0.002106</td>\n",
       "      <td>0.001202</td>\n",
       "      <td>-0.024952</td>\n",
       "      <td>-0.007080</td>\n",
       "      <td>-0.012874</td>\n",
       "      <td>-0.000340</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-10-31</th>\n",
       "      <td>-0.068257</td>\n",
       "      <td>-0.026400</td>\n",
       "      <td>-0.026712</td>\n",
       "      <td>-0.035206</td>\n",
       "      <td>-0.022298</td>\n",
       "      <td>-0.013751</td>\n",
       "      <td>-0.022298</td>\n",
       "      <td>-0.033380</td>\n",
       "      <td>-0.029932</td>\n",
       "      <td>0.008262</td>\n",
       "      <td>-0.076519</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-11-30</th>\n",
       "      <td>0.005351</td>\n",
       "      <td>-0.021096</td>\n",
       "      <td>0.009551</td>\n",
       "      <td>-0.004467</td>\n",
       "      <td>0.005741</td>\n",
       "      <td>0.011742</td>\n",
       "      <td>-0.004673</td>\n",
       "      <td>-0.001100</td>\n",
       "      <td>0.010682</td>\n",
       "      <td>0.005062</td>\n",
       "      <td>0.000289</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-31</th>\n",
       "      <td>-0.023762</td>\n",
       "      <td>-0.023652</td>\n",
       "      <td>-0.021338</td>\n",
       "      <td>-0.023467</td>\n",
       "      <td>-0.014802</td>\n",
       "      <td>-0.012190</td>\n",
       "      <td>-0.023572</td>\n",
       "      <td>-0.026295</td>\n",
       "      <td>0.005428</td>\n",
       "      <td>-0.050056</td>\n",
       "      <td>0.026293</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>288 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "sort              P1        P2        P3        P4        P5        P6  \\\n",
       "month                                                                    \n",
       "2000-01-31  0.128892  0.125095  0.109649  0.164682  0.134155  0.117154   \n",
       "2000-02-29  0.148460  0.098851  0.122838  0.084378  0.193957  0.095636   \n",
       "2000-03-31  0.028538  0.056167  0.088460  0.093958  0.115092  0.082248   \n",
       "2000-04-30 -0.005793  0.018555  0.037055  0.023933  0.009921  0.018328   \n",
       "2000-05-31  0.019856  0.013618  0.007191  0.016574  0.034658  0.026428   \n",
       "...              ...       ...       ...       ...       ...       ...   \n",
       "2023-08-31 -0.048515 -0.047374 -0.049198 -0.064861 -0.052590 -0.056458   \n",
       "2023-09-30 -0.013215 -0.008910 -0.008950  0.000798  0.000158  0.002106   \n",
       "2023-10-31 -0.068257 -0.026400 -0.026712 -0.035206 -0.022298 -0.013751   \n",
       "2023-11-30  0.005351 -0.021096  0.009551 -0.004467  0.005741  0.011742   \n",
       "2023-12-31 -0.023762 -0.023652 -0.021338 -0.023467 -0.014802 -0.012190   \n",
       "\n",
       "sort              P7        P8        P9      Pmax  My_portfolio  \n",
       "month                                                             \n",
       "2000-01-31  0.154231  0.133388  0.189671  0.277708     -0.148816  \n",
       "2000-02-29  0.080466  0.102473  0.169644  0.125983      0.022476  \n",
       "2000-03-31  0.079722  0.081513  0.040770 -0.044828      0.073366  \n",
       "2000-04-30  0.021396  0.004873 -0.011356 -0.015714      0.009921  \n",
       "2000-05-31  0.025010  0.058083  0.021637  0.036778     -0.016922  \n",
       "...              ...       ...       ...       ...           ...  \n",
       "2023-08-31 -0.054358 -0.052533 -0.059833 -0.069041      0.020526  \n",
       "2023-09-30  0.001202 -0.024952 -0.007080 -0.012874     -0.000340  \n",
       "2023-10-31 -0.022298 -0.033380 -0.029932  0.008262     -0.076519  \n",
       "2023-11-30 -0.004673 -0.001100  0.010682  0.005062      0.000289  \n",
       "2023-12-31 -0.023572 -0.026295  0.005428 -0.050056      0.026293  \n",
       "\n",
       "[288 rows x 11 columns]"
      ]
     },
     "execution_count": 190,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "portfolio_mom=portfolio_mom['2000':]\n",
    "portfolio_mom"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 191,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                            OLS Regression Results                            \n",
      "==============================================================================\n",
      "Dep. Variable:           My_portfolio   R-squared:                       0.000\n",
      "Model:                            OLS   Adj. R-squared:                  0.000\n",
      "Method:                 Least Squares   F-statistic:                       nan\n",
      "Date:                Wed, 27 Nov 2024   Prob (F-statistic):                nan\n",
      "Time:                        11:12:51   Log-Likelihood:                 368.00\n",
      "No. Observations:                 288   AIC:                            -734.0\n",
      "Df Residuals:                     287   BIC:                            -730.3\n",
      "Df Model:                           0                                         \n",
      "Covariance Type:                  HAC                                         \n",
      "==============================================================================\n",
      "                 coef    std err          z      P>|z|      [0.025      0.975]\n",
      "------------------------------------------------------------------------------\n",
      "Intercept      0.0089      0.004      2.375      0.018       0.002       0.016\n",
      "==============================================================================\n",
      "Omnibus:                       29.971   Durbin-Watson:                   2.065\n",
      "Prob(Omnibus):                  0.000   Jarque-Bera (JB):              131.340\n",
      "Skew:                          -0.217   Prob(JB):                     3.02e-29\n",
      "Kurtosis:                       6.280   Cond. No.                         1.00\n",
      "==============================================================================\n",
      "\n",
      "Notes:\n",
      "[1] Standard Errors are heteroscedasticity and autocorrelation robust (HAC) using 6 lags and without small sample correction\n"
     ]
    }
   ],
   "source": [
    "model_mom=smf.ols('My_portfolio~1',data=portfolio_mom).fit(\n",
    "    cov_type='HAC',cov_kwds={'maxlags':6})\n",
    "print(model_mom.summary())\n",
    "# 回归的结果和直接做均值t检验的结果是一样的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 192,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Preclose</th>\n",
       "      <th>Open</th>\n",
       "      <th>Highest</th>\n",
       "      <th>Lowest</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Money</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Day</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1990-12-19</th>\n",
       "      <td></td>\n",
       "      <td>96.050</td>\n",
       "      <td>99.980</td>\n",
       "      <td>95.790</td>\n",
       "      <td>99.980</td>\n",
       "      <td>126000.00</td>\n",
       "      <td>4.940000e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990-12-20</th>\n",
       "      <td>99.98</td>\n",
       "      <td>104.300</td>\n",
       "      <td>104.390</td>\n",
       "      <td>99.980</td>\n",
       "      <td>104.390</td>\n",
       "      <td>19700.00</td>\n",
       "      <td>8.400000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990-12-21</th>\n",
       "      <td>104.39</td>\n",
       "      <td>109.070</td>\n",
       "      <td>109.130</td>\n",
       "      <td>103.730</td>\n",
       "      <td>109.130</td>\n",
       "      <td>2800.00</td>\n",
       "      <td>1.600000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990-12-24</th>\n",
       "      <td>109.13</td>\n",
       "      <td>113.570</td>\n",
       "      <td>114.550</td>\n",
       "      <td>109.130</td>\n",
       "      <td>114.550</td>\n",
       "      <td>3200.00</td>\n",
       "      <td>3.100000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1990-12-25</th>\n",
       "      <td>114.55</td>\n",
       "      <td>120.090</td>\n",
       "      <td>120.250</td>\n",
       "      <td>114.550</td>\n",
       "      <td>120.250</td>\n",
       "      <td>1500.00</td>\n",
       "      <td>6.000000e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-09-24</th>\n",
       "      <td>2748.918</td>\n",
       "      <td>2770.754</td>\n",
       "      <td>2863.152</td>\n",
       "      <td>2761.372</td>\n",
       "      <td>2863.126</td>\n",
       "      <td>4776195.45</td>\n",
       "      <td>4.427953e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-09-25</th>\n",
       "      <td>2863.126</td>\n",
       "      <td>2901.419</td>\n",
       "      <td>2952.451</td>\n",
       "      <td>2889.048</td>\n",
       "      <td>2896.306</td>\n",
       "      <td>5682598.16</td>\n",
       "      <td>5.166981e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-09-26</th>\n",
       "      <td>2896.306</td>\n",
       "      <td>2893.745</td>\n",
       "      <td>3000.953</td>\n",
       "      <td>2889.014</td>\n",
       "      <td>3000.953</td>\n",
       "      <td>5763192.61</td>\n",
       "      <td>5.246691e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-09-27</th>\n",
       "      <td>3000.953</td>\n",
       "      <td>3049.103</td>\n",
       "      <td>3087.529</td>\n",
       "      <td>3017.445</td>\n",
       "      <td>3087.529</td>\n",
       "      <td>4922871.63</td>\n",
       "      <td>4.806126e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-09-30</th>\n",
       "      <td>3087.529</td>\n",
       "      <td>3194.722</td>\n",
       "      <td>3358.588</td>\n",
       "      <td>3153.697</td>\n",
       "      <td>3336.497</td>\n",
       "      <td>11023379.17</td>\n",
       "      <td>1.167773e+08</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8251 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            Preclose      Open   Highest    Lowest     Close       Volume  \\\n",
       "Day                                                                         \n",
       "1990-12-19              96.050    99.980    95.790    99.980    126000.00   \n",
       "1990-12-20     99.98   104.300   104.390    99.980   104.390     19700.00   \n",
       "1990-12-21    104.39   109.070   109.130   103.730   109.130      2800.00   \n",
       "1990-12-24    109.13   113.570   114.550   109.130   114.550      3200.00   \n",
       "1990-12-25    114.55   120.090   120.250   114.550   120.250      1500.00   \n",
       "...              ...       ...       ...       ...       ...          ...   \n",
       "2024-09-24  2748.918  2770.754  2863.152  2761.372  2863.126   4776195.45   \n",
       "2024-09-25  2863.126  2901.419  2952.451  2889.048  2896.306   5682598.16   \n",
       "2024-09-26  2896.306  2893.745  3000.953  2889.014  3000.953   5763192.61   \n",
       "2024-09-27  3000.953  3049.103  3087.529  3017.445  3087.529   4922871.63   \n",
       "2024-09-30  3087.529  3194.722  3358.588  3153.697  3336.497  11023379.17   \n",
       "\n",
       "                   Money  \n",
       "Day                       \n",
       "1990-12-19  4.940000e+05  \n",
       "1990-12-20  8.400000e+04  \n",
       "1990-12-21  1.600000e+04  \n",
       "1990-12-24  3.100000e+04  \n",
       "1990-12-25  6.000000e+03  \n",
       "...                  ...  \n",
       "2024-09-24  4.427953e+07  \n",
       "2024-09-25  5.166981e+07  \n",
       "2024-09-26  5.246691e+07  \n",
       "2024-09-27  4.806126e+07  \n",
       "2024-09-30  1.167773e+08  \n",
       "\n",
       "[8251 rows x 7 columns]"
      ]
     },
     "execution_count": 192,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Raw_return</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1995-01-31</th>\n",
       "      <td>-0.131631</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-02-28</th>\n",
       "      <td>-0.023694</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-03-31</th>\n",
       "      <td>0.177803</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-04-30</th>\n",
       "      <td>-0.103552</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1995-05-31</th>\n",
       "      <td>0.207922</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-05-31</th>\n",
       "      <td>-0.005801</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-30</th>\n",
       "      <td>-0.038684</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-07-31</th>\n",
       "      <td>-0.009656</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-08-31</th>\n",
       "      <td>-0.032849</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-09-30</th>\n",
       "      <td>0.173908</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>357 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            Raw_return\n",
       "month                 \n",
       "1995-01-31   -0.131631\n",
       "1995-02-28   -0.023694\n",
       "1995-03-31    0.177803\n",
       "1995-04-30   -0.103552\n",
       "1995-05-31    0.207922\n",
       "...                ...\n",
       "2024-05-31   -0.005801\n",
       "2024-06-30   -0.038684\n",
       "2024-07-31   -0.009656\n",
       "2024-08-31   -0.032849\n",
       "2024-09-30    0.173908\n",
       "\n",
       "[357 rows x 1 columns]"
      ]
     },
     "execution_count": 192,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pd.read_csv('datasets/000001.csv')\n",
    "data['Day'] = pd.to_datetime(data['Day'],format='%Y/%m/%d')\n",
    "data.set_index('Day', inplace = True)\n",
    "data.sort_values(by = ['Day'],axis=0, ascending=True)\n",
    "data_new = data['1995-01':'2024-09'].copy()\n",
    "data_new['Close'] = pd.to_numeric(data_new['Close'])\n",
    "data_new['Preclose'] = pd.to_numeric(data_new['Preclose'])\n",
    "data_new['Raw_return'] = data_new['Close'] / data_new['Preclose'] - 1\n",
    "Month_data = data_new.resample('ME')['Raw_return'].apply(lambda x: (1+x).prod() - 1).to_frame()\n",
    "Month_data.reset_index(inplace = True)\n",
    "Month_data.rename(columns = {'Day':'month'}, inplace = True)\n",
    "Month_data.set_index('month', inplace = True)\n",
    "Month_data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 什么是$\\beta$和$\\alpha$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 193,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>P1</th>\n",
       "      <th>P2</th>\n",
       "      <th>P3</th>\n",
       "      <th>P4</th>\n",
       "      <th>P5</th>\n",
       "      <th>P6</th>\n",
       "      <th>P7</th>\n",
       "      <th>P8</th>\n",
       "      <th>P9</th>\n",
       "      <th>Pmax</th>\n",
       "      <th>My_portfolio</th>\n",
       "      <th>Raw_return</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2000-01-31</th>\n",
       "      <td>0.128892</td>\n",
       "      <td>0.125095</td>\n",
       "      <td>0.109649</td>\n",
       "      <td>0.164682</td>\n",
       "      <td>0.134155</td>\n",
       "      <td>0.117154</td>\n",
       "      <td>0.154231</td>\n",
       "      <td>0.133388</td>\n",
       "      <td>0.189671</td>\n",
       "      <td>0.277708</td>\n",
       "      <td>-0.148816</td>\n",
       "      <td>0.123242</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-02-29</th>\n",
       "      <td>0.148460</td>\n",
       "      <td>0.098851</td>\n",
       "      <td>0.122838</td>\n",
       "      <td>0.084378</td>\n",
       "      <td>0.193957</td>\n",
       "      <td>0.095636</td>\n",
       "      <td>0.080466</td>\n",
       "      <td>0.102473</td>\n",
       "      <td>0.169644</td>\n",
       "      <td>0.125983</td>\n",
       "      <td>0.022476</td>\n",
       "      <td>0.116990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-03-31</th>\n",
       "      <td>0.028538</td>\n",
       "      <td>0.056167</td>\n",
       "      <td>0.088460</td>\n",
       "      <td>0.093958</td>\n",
       "      <td>0.115092</td>\n",
       "      <td>0.082248</td>\n",
       "      <td>0.079722</td>\n",
       "      <td>0.081513</td>\n",
       "      <td>0.040770</td>\n",
       "      <td>-0.044828</td>\n",
       "      <td>0.073366</td>\n",
       "      <td>0.049948</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-04-30</th>\n",
       "      <td>-0.005793</td>\n",
       "      <td>0.018555</td>\n",
       "      <td>0.037055</td>\n",
       "      <td>0.023933</td>\n",
       "      <td>0.009921</td>\n",
       "      <td>0.018328</td>\n",
       "      <td>0.021396</td>\n",
       "      <td>0.004873</td>\n",
       "      <td>-0.011356</td>\n",
       "      <td>-0.015714</td>\n",
       "      <td>0.009921</td>\n",
       "      <td>0.020053</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-05-31</th>\n",
       "      <td>0.019856</td>\n",
       "      <td>0.013618</td>\n",
       "      <td>0.007191</td>\n",
       "      <td>0.016574</td>\n",
       "      <td>0.034658</td>\n",
       "      <td>0.026428</td>\n",
       "      <td>0.025010</td>\n",
       "      <td>0.058083</td>\n",
       "      <td>0.021637</td>\n",
       "      <td>0.036778</td>\n",
       "      <td>-0.016922</td>\n",
       "      <td>0.031710</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-08-31</th>\n",
       "      <td>-0.048515</td>\n",
       "      <td>-0.047374</td>\n",
       "      <td>-0.049198</td>\n",
       "      <td>-0.064861</td>\n",
       "      <td>-0.052590</td>\n",
       "      <td>-0.056458</td>\n",
       "      <td>-0.054358</td>\n",
       "      <td>-0.052533</td>\n",
       "      <td>-0.059833</td>\n",
       "      <td>-0.069041</td>\n",
       "      <td>0.020526</td>\n",
       "      <td>-0.052009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-09-30</th>\n",
       "      <td>-0.013215</td>\n",
       "      <td>-0.008910</td>\n",
       "      <td>-0.008950</td>\n",
       "      <td>0.000798</td>\n",
       "      <td>0.000158</td>\n",
       "      <td>0.002106</td>\n",
       "      <td>0.001202</td>\n",
       "      <td>-0.024952</td>\n",
       "      <td>-0.007080</td>\n",
       "      <td>-0.012874</td>\n",
       "      <td>-0.000340</td>\n",
       "      <td>-0.003013</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-10-31</th>\n",
       "      <td>-0.068257</td>\n",
       "      <td>-0.026400</td>\n",
       "      <td>-0.026712</td>\n",
       "      <td>-0.035206</td>\n",
       "      <td>-0.022298</td>\n",
       "      <td>-0.013751</td>\n",
       "      <td>-0.022298</td>\n",
       "      <td>-0.033380</td>\n",
       "      <td>-0.029932</td>\n",
       "      <td>0.008262</td>\n",
       "      <td>-0.076519</td>\n",
       "      <td>-0.029483</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-11-30</th>\n",
       "      <td>0.005351</td>\n",
       "      <td>-0.021096</td>\n",
       "      <td>0.009551</td>\n",
       "      <td>-0.004467</td>\n",
       "      <td>0.005741</td>\n",
       "      <td>0.011742</td>\n",
       "      <td>-0.004673</td>\n",
       "      <td>-0.001100</td>\n",
       "      <td>0.010682</td>\n",
       "      <td>0.005062</td>\n",
       "      <td>0.000289</td>\n",
       "      <td>0.003611</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-31</th>\n",
       "      <td>-0.023762</td>\n",
       "      <td>-0.023652</td>\n",
       "      <td>-0.021338</td>\n",
       "      <td>-0.023467</td>\n",
       "      <td>-0.014802</td>\n",
       "      <td>-0.012190</td>\n",
       "      <td>-0.023572</td>\n",
       "      <td>-0.026295</td>\n",
       "      <td>0.005428</td>\n",
       "      <td>-0.050056</td>\n",
       "      <td>0.026293</td>\n",
       "      <td>-0.018067</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>288 rows × 12 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  P1        P2        P3        P4        P5        P6  \\\n",
       "month                                                                    \n",
       "2000-01-31  0.128892  0.125095  0.109649  0.164682  0.134155  0.117154   \n",
       "2000-02-29  0.148460  0.098851  0.122838  0.084378  0.193957  0.095636   \n",
       "2000-03-31  0.028538  0.056167  0.088460  0.093958  0.115092  0.082248   \n",
       "2000-04-30 -0.005793  0.018555  0.037055  0.023933  0.009921  0.018328   \n",
       "2000-05-31  0.019856  0.013618  0.007191  0.016574  0.034658  0.026428   \n",
       "...              ...       ...       ...       ...       ...       ...   \n",
       "2023-08-31 -0.048515 -0.047374 -0.049198 -0.064861 -0.052590 -0.056458   \n",
       "2023-09-30 -0.013215 -0.008910 -0.008950  0.000798  0.000158  0.002106   \n",
       "2023-10-31 -0.068257 -0.026400 -0.026712 -0.035206 -0.022298 -0.013751   \n",
       "2023-11-30  0.005351 -0.021096  0.009551 -0.004467  0.005741  0.011742   \n",
       "2023-12-31 -0.023762 -0.023652 -0.021338 -0.023467 -0.014802 -0.012190   \n",
       "\n",
       "                  P7        P8        P9      Pmax  My_portfolio  Raw_return  \n",
       "month                                                                         \n",
       "2000-01-31  0.154231  0.133388  0.189671  0.277708     -0.148816    0.123242  \n",
       "2000-02-29  0.080466  0.102473  0.169644  0.125983      0.022476    0.116990  \n",
       "2000-03-31  0.079722  0.081513  0.040770 -0.044828      0.073366    0.049948  \n",
       "2000-04-30  0.021396  0.004873 -0.011356 -0.015714      0.009921    0.020053  \n",
       "2000-05-31  0.025010  0.058083  0.021637  0.036778     -0.016922    0.031710  \n",
       "...              ...       ...       ...       ...           ...         ...  \n",
       "2023-08-31 -0.054358 -0.052533 -0.059833 -0.069041      0.020526   -0.052009  \n",
       "2023-09-30  0.001202 -0.024952 -0.007080 -0.012874     -0.000340   -0.003013  \n",
       "2023-10-31 -0.022298 -0.033380 -0.029932  0.008262     -0.076519   -0.029483  \n",
       "2023-11-30 -0.004673 -0.001100  0.010682  0.005062      0.000289    0.003611  \n",
       "2023-12-31 -0.023572 -0.026295  0.005428 -0.050056      0.026293   -0.018067  \n",
       "\n",
       "[288 rows x 12 columns]"
      ]
     },
     "execution_count": 193,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MYPORT=pd.merge(portfolio_mom,Month_data,how='left',on='month')\n",
    "MYPORT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 194,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                            OLS Regression Results                            \n",
      "==============================================================================\n",
      "Dep. Variable:           My_portfolio   R-squared:                       0.011\n",
      "Model:                            OLS   Adj. R-squared:                  0.008\n",
      "Method:                 Least Squares   F-statistic:                     1.134\n",
      "Date:                Wed, 27 Nov 2024   Prob (F-statistic):              0.288\n",
      "Time:                        11:12:51   Log-Likelihood:                 369.66\n",
      "No. Observations:                 288   AIC:                            -735.3\n",
      "Df Residuals:                     286   BIC:                            -728.0\n",
      "Df Model:                           1                                         \n",
      "Covariance Type:                  HAC                                         \n",
      "==============================================================================\n",
      "                 coef    std err          z      P>|z|      [0.025      0.975]\n",
      "------------------------------------------------------------------------------\n",
      "Intercept      0.0094      0.003      2.712      0.007       0.003       0.016\n",
      "Raw_return    -0.1021      0.096     -1.065      0.287      -0.290       0.086\n",
      "==============================================================================\n",
      "Omnibus:                       23.243   Durbin-Watson:                   2.109\n",
      "Prob(Omnibus):                  0.000   Jarque-Bera (JB):               88.765\n",
      "Skew:                          -0.050   Prob(JB):                     5.31e-20\n",
      "Kurtosis:                       5.718   Cond. No.                         14.1\n",
      "==============================================================================\n",
      "\n",
      "Notes:\n",
      "[1] Standard Errors are heteroscedasticity and autocorrelation robust (HAC) using 6 lags and without small sample correction\n"
     ]
    }
   ],
   "source": [
    "model_mom=smf.ols('My_portfolio~Raw_return',data=MYPORT).fit(\n",
    "    cov_type='HAC',cov_kwds={'maxlags':6})\n",
    "print(model_mom.summary())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$$\n",
    "R_{mom,t}=0.0094-0.1021*R_{m,t}\n",
    "$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- $\\beta$是负的"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 策略的价格 变动"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 195,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>P1</th>\n",
       "      <th>P2</th>\n",
       "      <th>P3</th>\n",
       "      <th>P4</th>\n",
       "      <th>P5</th>\n",
       "      <th>P6</th>\n",
       "      <th>P7</th>\n",
       "      <th>P8</th>\n",
       "      <th>P9</th>\n",
       "      <th>Pmax</th>\n",
       "      <th>My_portfolio</th>\n",
       "      <th>Raw_return</th>\n",
       "      <th>My_portfolio_price</th>\n",
       "      <th>Pmax_price</th>\n",
       "      <th>P1_price</th>\n",
       "      <th>Market_price</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>month</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2000-01-31</th>\n",
       "      <td>0.128892</td>\n",
       "      <td>0.125095</td>\n",
       "      <td>0.109649</td>\n",
       "      <td>0.164682</td>\n",
       "      <td>0.134155</td>\n",
       "      <td>0.117154</td>\n",
       "      <td>0.154231</td>\n",
       "      <td>0.133388</td>\n",
       "      <td>0.189671</td>\n",
       "      <td>0.277708</td>\n",
       "      <td>-0.148816</td>\n",
       "      <td>0.123242</td>\n",
       "      <td>0.851184</td>\n",
       "      <td>1.277708</td>\n",
       "      <td>1.128892</td>\n",
       "      <td>1.123242</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-02-29</th>\n",
       "      <td>0.148460</td>\n",
       "      <td>0.098851</td>\n",
       "      <td>0.122838</td>\n",
       "      <td>0.084378</td>\n",
       "      <td>0.193957</td>\n",
       "      <td>0.095636</td>\n",
       "      <td>0.080466</td>\n",
       "      <td>0.102473</td>\n",
       "      <td>0.169644</td>\n",
       "      <td>0.125983</td>\n",
       "      <td>0.022476</td>\n",
       "      <td>0.116990</td>\n",
       "      <td>0.870316</td>\n",
       "      <td>1.438677</td>\n",
       "      <td>1.296487</td>\n",
       "      <td>1.254650</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-03-31</th>\n",
       "      <td>0.028538</td>\n",
       "      <td>0.056167</td>\n",
       "      <td>0.088460</td>\n",
       "      <td>0.093958</td>\n",
       "      <td>0.115092</td>\n",
       "      <td>0.082248</td>\n",
       "      <td>0.079722</td>\n",
       "      <td>0.081513</td>\n",
       "      <td>0.040770</td>\n",
       "      <td>-0.044828</td>\n",
       "      <td>0.073366</td>\n",
       "      <td>0.049948</td>\n",
       "      <td>0.934168</td>\n",
       "      <td>1.374184</td>\n",
       "      <td>1.333486</td>\n",
       "      <td>1.317318</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-04-30</th>\n",
       "      <td>-0.005793</td>\n",
       "      <td>0.018555</td>\n",
       "      <td>0.037055</td>\n",
       "      <td>0.023933</td>\n",
       "      <td>0.009921</td>\n",
       "      <td>0.018328</td>\n",
       "      <td>0.021396</td>\n",
       "      <td>0.004873</td>\n",
       "      <td>-0.011356</td>\n",
       "      <td>-0.015714</td>\n",
       "      <td>0.009921</td>\n",
       "      <td>0.020053</td>\n",
       "      <td>0.943436</td>\n",
       "      <td>1.352590</td>\n",
       "      <td>1.325762</td>\n",
       "      <td>1.343734</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2000-05-31</th>\n",
       "      <td>0.019856</td>\n",
       "      <td>0.013618</td>\n",
       "      <td>0.007191</td>\n",
       "      <td>0.016574</td>\n",
       "      <td>0.034658</td>\n",
       "      <td>0.026428</td>\n",
       "      <td>0.025010</td>\n",
       "      <td>0.058083</td>\n",
       "      <td>0.021637</td>\n",
       "      <td>0.036778</td>\n",
       "      <td>-0.016922</td>\n",
       "      <td>0.031710</td>\n",
       "      <td>0.927471</td>\n",
       "      <td>1.402335</td>\n",
       "      <td>1.352086</td>\n",
       "      <td>1.386344</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-08-31</th>\n",
       "      <td>-0.048515</td>\n",
       "      <td>-0.047374</td>\n",
       "      <td>-0.049198</td>\n",
       "      <td>-0.064861</td>\n",
       "      <td>-0.052590</td>\n",
       "      <td>-0.056458</td>\n",
       "      <td>-0.054358</td>\n",
       "      <td>-0.052533</td>\n",
       "      <td>-0.059833</td>\n",
       "      <td>-0.069041</td>\n",
       "      <td>0.020526</td>\n",
       "      <td>-0.052009</td>\n",
       "      <td>6.946370</td>\n",
       "      <td>0.316197</td>\n",
       "      <td>4.670596</td>\n",
       "      <td>2.282984</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-09-30</th>\n",
       "      <td>-0.013215</td>\n",
       "      <td>-0.008910</td>\n",
       "      <td>-0.008950</td>\n",
       "      <td>0.000798</td>\n",
       "      <td>0.000158</td>\n",
       "      <td>0.002106</td>\n",
       "      <td>0.001202</td>\n",
       "      <td>-0.024952</td>\n",
       "      <td>-0.007080</td>\n",
       "      <td>-0.012874</td>\n",
       "      <td>-0.000340</td>\n",
       "      <td>-0.003013</td>\n",
       "      <td>6.944005</td>\n",
       "      <td>0.312126</td>\n",
       "      <td>4.608875</td>\n",
       "      <td>2.276105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-10-31</th>\n",
       "      <td>-0.068257</td>\n",
       "      <td>-0.026400</td>\n",
       "      <td>-0.026712</td>\n",
       "      <td>-0.035206</td>\n",
       "      <td>-0.022298</td>\n",
       "      <td>-0.013751</td>\n",
       "      <td>-0.022298</td>\n",
       "      <td>-0.033380</td>\n",
       "      <td>-0.029932</td>\n",
       "      <td>0.008262</td>\n",
       "      <td>-0.076519</td>\n",
       "      <td>-0.029483</td>\n",
       "      <td>6.412660</td>\n",
       "      <td>0.314704</td>\n",
       "      <td>4.294287</td>\n",
       "      <td>2.208999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-11-30</th>\n",
       "      <td>0.005351</td>\n",
       "      <td>-0.021096</td>\n",
       "      <td>0.009551</td>\n",
       "      <td>-0.004467</td>\n",
       "      <td>0.005741</td>\n",
       "      <td>0.011742</td>\n",
       "      <td>-0.004673</td>\n",
       "      <td>-0.001100</td>\n",
       "      <td>0.010682</td>\n",
       "      <td>0.005062</td>\n",
       "      <td>0.000289</td>\n",
       "      <td>0.003611</td>\n",
       "      <td>6.414512</td>\n",
       "      <td>0.316297</td>\n",
       "      <td>4.317264</td>\n",
       "      <td>2.216977</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-31</th>\n",
       "      <td>-0.023762</td>\n",
       "      <td>-0.023652</td>\n",
       "      <td>-0.021338</td>\n",
       "      <td>-0.023467</td>\n",
       "      <td>-0.014802</td>\n",
       "      <td>-0.012190</td>\n",
       "      <td>-0.023572</td>\n",
       "      <td>-0.026295</td>\n",
       "      <td>0.005428</td>\n",
       "      <td>-0.050056</td>\n",
       "      <td>0.026293</td>\n",
       "      <td>-0.018067</td>\n",
       "      <td>6.583172</td>\n",
       "      <td>0.300465</td>\n",
       "      <td>4.214677</td>\n",
       "      <td>2.176922</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>288 rows × 16 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                  P1        P2        P3        P4        P5        P6  \\\n",
       "month                                                                    \n",
       "2000-01-31  0.128892  0.125095  0.109649  0.164682  0.134155  0.117154   \n",
       "2000-02-29  0.148460  0.098851  0.122838  0.084378  0.193957  0.095636   \n",
       "2000-03-31  0.028538  0.056167  0.088460  0.093958  0.115092  0.082248   \n",
       "2000-04-30 -0.005793  0.018555  0.037055  0.023933  0.009921  0.018328   \n",
       "2000-05-31  0.019856  0.013618  0.007191  0.016574  0.034658  0.026428   \n",
       "...              ...       ...       ...       ...       ...       ...   \n",
       "2023-08-31 -0.048515 -0.047374 -0.049198 -0.064861 -0.052590 -0.056458   \n",
       "2023-09-30 -0.013215 -0.008910 -0.008950  0.000798  0.000158  0.002106   \n",
       "2023-10-31 -0.068257 -0.026400 -0.026712 -0.035206 -0.022298 -0.013751   \n",
       "2023-11-30  0.005351 -0.021096  0.009551 -0.004467  0.005741  0.011742   \n",
       "2023-12-31 -0.023762 -0.023652 -0.021338 -0.023467 -0.014802 -0.012190   \n",
       "\n",
       "                  P7        P8        P9      Pmax  My_portfolio  Raw_return  \\\n",
       "month                                                                          \n",
       "2000-01-31  0.154231  0.133388  0.189671  0.277708     -0.148816    0.123242   \n",
       "2000-02-29  0.080466  0.102473  0.169644  0.125983      0.022476    0.116990   \n",
       "2000-03-31  0.079722  0.081513  0.040770 -0.044828      0.073366    0.049948   \n",
       "2000-04-30  0.021396  0.004873 -0.011356 -0.015714      0.009921    0.020053   \n",
       "2000-05-31  0.025010  0.058083  0.021637  0.036778     -0.016922    0.031710   \n",
       "...              ...       ...       ...       ...           ...         ...   \n",
       "2023-08-31 -0.054358 -0.052533 -0.059833 -0.069041      0.020526   -0.052009   \n",
       "2023-09-30  0.001202 -0.024952 -0.007080 -0.012874     -0.000340   -0.003013   \n",
       "2023-10-31 -0.022298 -0.033380 -0.029932  0.008262     -0.076519   -0.029483   \n",
       "2023-11-30 -0.004673 -0.001100  0.010682  0.005062      0.000289    0.003611   \n",
       "2023-12-31 -0.023572 -0.026295  0.005428 -0.050056      0.026293   -0.018067   \n",
       "\n",
       "            My_portfolio_price  Pmax_price  P1_price  Market_price  \n",
       "month                                                               \n",
       "2000-01-31            0.851184    1.277708  1.128892      1.123242  \n",
       "2000-02-29            0.870316    1.438677  1.296487      1.254650  \n",
       "2000-03-31            0.934168    1.374184  1.333486      1.317318  \n",
       "2000-04-30            0.943436    1.352590  1.325762      1.343734  \n",
       "2000-05-31            0.927471    1.402335  1.352086      1.386344  \n",
       "...                        ...         ...       ...           ...  \n",
       "2023-08-31            6.946370    0.316197  4.670596      2.282984  \n",
       "2023-09-30            6.944005    0.312126  4.608875      2.276105  \n",
       "2023-10-31            6.412660    0.314704  4.294287      2.208999  \n",
       "2023-11-30            6.414512    0.316297  4.317264      2.216977  \n",
       "2023-12-31            6.583172    0.300465  4.214677      2.176922  \n",
       "\n",
       "[288 rows x 16 columns]"
      ]
     },
     "execution_count": 195,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#还原投资组合的价格\n",
    "MYPORT['My_portfolio_price']=(MYPORT['My_portfolio']+1).cumprod()\n",
    "MYPORT['Pmax_price']=(MYPORT['Pmax']+1).cumprod()\n",
    "MYPORT['P1_price']=(MYPORT['P1']+1).cumprod()\n",
    "MYPORT['Market_price']=(MYPORT['Raw_return']+1).cumprod()\n",
    "MYPORT\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 价格图片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 200,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"976.3625pt\" height=\"363.718125pt\" viewBox=\"0 0 976.3625 363.718125\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n",
       " <metadata>\n",
       "  <rdf:RDF xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:cc=\"http://creativecommons.org/ns#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n",
       "   <cc:Work>\n",
       "    <dc:type rdf:resource=\"http://purl.org/dc/dcmitype/StillImage\"/>\n",
       "    <dc:date>2024-11-27T11:15:12.151273</dc:date>\n",
       "    <dc:format>image/svg+xml</dc:format>\n",
       "    <dc:creator>\n",
       "     <cc:Agent>\n",
       "      <dc:title>Matplotlib v3.8.4, https://matplotlib.org/</dc:title>\n",
       "     </cc:Agent>\n",
       "    </dc:creator>\n",
       "   </cc:Work>\n",
       "  </rdf:RDF>\n",
       " </metadata>\n",
       " <defs>\n",
       "  <style type=\"text/css\">*{stroke-linejoin: round; stroke-linecap: butt}</style>\n",
       " </defs>\n",
       " <g id=\"figure_1\">\n",
       "  <g id=\"patch_1\">\n",
       "   <path d=\"M 0 363.718125 \n",
       "L 976.3625 363.718125 \n",
       "L 976.3625 0 \n",
       "L 0 0 \n",
       "z\n",
       "\" style=\"fill: #ffffff\"/>\n",
       "  </g>\n",
       "  <g id=\"axes_1\">\n",
       "   <g id=\"patch_2\">\n",
       "    <path d=\"M 20.5625 339.84 \n",
       "L 969.1625 339.84 \n",
       "L 969.1625 7.2 \n",
       "L 20.5625 7.2 \n",
       "z\n",
       "\" style=\"fill: #ffffff\"/>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_1\">\n",
       "    <g id=\"xtick_1\">\n",
       "     <g id=\"line2d_1\">\n",
       "      <path d=\"M 60.718929 339.84 \n",
       "L 60.718929 7.2 \n",
       "\" clip-path=\"url(#p8d3d213286)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_2\">\n",
       "      <defs>\n",
       "       <path id=\"m13cda5a59d\" d=\"M 0 0 \n",
       "L 0 3.5 \n",
       "\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </defs>\n",
       "      <g>\n",
       "       <use xlink:href=\"#m13cda5a59d\" x=\"60.718929\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_1\">\n",
       "      <!-- 2000 -->\n",
       "      <g transform=\"translate(47.993929 354.438437) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-32\" d=\"M 1228 531 \n",
       "L 3431 531 \n",
       "L 3431 0 \n",
       "L 469 0 \n",
       "L 469 531 \n",
       "Q 828 903 1448 1529 \n",
       "Q 2069 2156 2228 2338 \n",
       "Q 2531 2678 2651 2914 \n",
       "Q 2772 3150 2772 3378 \n",
       "Q 2772 3750 2511 3984 \n",
       "Q 2250 4219 1831 4219 \n",
       "Q 1534 4219 1204 4116 \n",
       "Q 875 4013 500 3803 \n",
       "L 500 4441 \n",
       "Q 881 4594 1212 4672 \n",
       "Q 1544 4750 1819 4750 \n",
       "Q 2544 4750 2975 4387 \n",
       "Q 3406 4025 3406 3419 \n",
       "Q 3406 3131 3298 2873 \n",
       "Q 3191 2616 2906 2266 \n",
       "Q 2828 2175 2409 1742 \n",
       "Q 1991 1309 1228 531 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "        <path id=\"DejaVuSans-30\" d=\"M 2034 4250 \n",
       "Q 1547 4250 1301 3770 \n",
       "Q 1056 3291 1056 2328 \n",
       "Q 1056 1369 1301 889 \n",
       "Q 1547 409 2034 409 \n",
       "Q 2525 409 2770 889 \n",
       "Q 3016 1369 3016 2328 \n",
       "Q 3016 3291 2770 3770 \n",
       "Q 2525 4250 2034 4250 \n",
       "z\n",
       "M 2034 4750 \n",
       "Q 2819 4750 3233 4129 \n",
       "Q 3647 3509 3647 2328 \n",
       "Q 3647 1150 3233 529 \n",
       "Q 2819 -91 2034 -91 \n",
       "Q 1250 -91 836 529 \n",
       "Q 422 1150 422 2328 \n",
       "Q 422 3509 836 4129 \n",
       "Q 1250 4750 2034 4750 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-32\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"127.246094\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"190.869141\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_2\">\n",
       "     <g id=\"line2d_3\">\n",
       "      <path d=\"M 204.956282 339.84 \n",
       "L 204.956282 7.2 \n",
       "\" clip-path=\"url(#p8d3d213286)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_4\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m13cda5a59d\" x=\"204.956282\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_2\">\n",
       "      <!-- 2004 -->\n",
       "      <g transform=\"translate(192.231282 354.438437) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-34\" d=\"M 2419 4116 \n",
       "L 825 1625 \n",
       "L 2419 1625 \n",
       "L 2419 4116 \n",
       "z\n",
       "M 2253 4666 \n",
       "L 3047 4666 \n",
       "L 3047 1625 \n",
       "L 3713 1625 \n",
       "L 3713 1100 \n",
       "L 3047 1100 \n",
       "L 3047 0 \n",
       "L 2419 0 \n",
       "L 2419 1100 \n",
       "L 313 1100 \n",
       "L 313 1709 \n",
       "L 2253 4666 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-32\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"127.246094\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-34\" x=\"190.869141\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_3\">\n",
       "     <g id=\"line2d_5\">\n",
       "      <path d=\"M 349.193634 339.84 \n",
       "L 349.193634 7.2 \n",
       "\" clip-path=\"url(#p8d3d213286)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_6\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m13cda5a59d\" x=\"349.193634\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_3\">\n",
       "      <!-- 2008 -->\n",
       "      <g transform=\"translate(336.468634 354.438437) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-38\" d=\"M 2034 2216 \n",
       "Q 1584 2216 1326 1975 \n",
       "Q 1069 1734 1069 1313 \n",
       "Q 1069 891 1326 650 \n",
       "Q 1584 409 2034 409 \n",
       "Q 2484 409 2743 651 \n",
       "Q 3003 894 3003 1313 \n",
       "Q 3003 1734 2745 1975 \n",
       "Q 2488 2216 2034 2216 \n",
       "z\n",
       "M 1403 2484 \n",
       "Q 997 2584 770 2862 \n",
       "Q 544 3141 544 3541 \n",
       "Q 544 4100 942 4425 \n",
       "Q 1341 4750 2034 4750 \n",
       "Q 2731 4750 3128 4425 \n",
       "Q 3525 4100 3525 3541 \n",
       "Q 3525 3141 3298 2862 \n",
       "Q 3072 2584 2669 2484 \n",
       "Q 3125 2378 3379 2068 \n",
       "Q 3634 1759 3634 1313 \n",
       "Q 3634 634 3220 271 \n",
       "Q 2806 -91 2034 -91 \n",
       "Q 1263 -91 848 271 \n",
       "Q 434 634 434 1313 \n",
       "Q 434 1759 690 2068 \n",
       "Q 947 2378 1403 2484 \n",
       "z\n",
       "M 1172 3481 \n",
       "Q 1172 3119 1398 2916 \n",
       "Q 1625 2713 2034 2713 \n",
       "Q 2441 2713 2670 2916 \n",
       "Q 2900 3119 2900 3481 \n",
       "Q 2900 3844 2670 4047 \n",
       "Q 2441 4250 2034 4250 \n",
       "Q 1625 4250 1398 4047 \n",
       "Q 1172 3844 1172 3481 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-32\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"127.246094\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-38\" x=\"190.869141\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_4\">\n",
       "     <g id=\"line2d_7\">\n",
       "      <path d=\"M 493.430986 339.84 \n",
       "L 493.430986 7.2 \n",
       "\" clip-path=\"url(#p8d3d213286)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_8\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m13cda5a59d\" x=\"493.430986\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_4\">\n",
       "      <!-- 2012 -->\n",
       "      <g transform=\"translate(480.705986 354.438437) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-31\" d=\"M 794 531 \n",
       "L 1825 531 \n",
       "L 1825 4091 \n",
       "L 703 3866 \n",
       "L 703 4441 \n",
       "L 1819 4666 \n",
       "L 2450 4666 \n",
       "L 2450 531 \n",
       "L 3481 531 \n",
       "L 3481 0 \n",
       "L 794 0 \n",
       "L 794 531 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-32\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-31\" x=\"127.246094\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-32\" x=\"190.869141\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_5\">\n",
       "     <g id=\"line2d_9\">\n",
       "      <path d=\"M 637.668339 339.84 \n",
       "L 637.668339 7.2 \n",
       "\" clip-path=\"url(#p8d3d213286)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_10\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m13cda5a59d\" x=\"637.668339\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_5\">\n",
       "      <!-- 2016 -->\n",
       "      <g transform=\"translate(624.943339 354.438437) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-36\" d=\"M 2113 2584 \n",
       "Q 1688 2584 1439 2293 \n",
       "Q 1191 2003 1191 1497 \n",
       "Q 1191 994 1439 701 \n",
       "Q 1688 409 2113 409 \n",
       "Q 2538 409 2786 701 \n",
       "Q 3034 994 3034 1497 \n",
       "Q 3034 2003 2786 2293 \n",
       "Q 2538 2584 2113 2584 \n",
       "z\n",
       "M 3366 4563 \n",
       "L 3366 3988 \n",
       "Q 3128 4100 2886 4159 \n",
       "Q 2644 4219 2406 4219 \n",
       "Q 1781 4219 1451 3797 \n",
       "Q 1122 3375 1075 2522 \n",
       "Q 1259 2794 1537 2939 \n",
       "Q 1816 3084 2150 3084 \n",
       "Q 2853 3084 3261 2657 \n",
       "Q 3669 2231 3669 1497 \n",
       "Q 3669 778 3244 343 \n",
       "Q 2819 -91 2113 -91 \n",
       "Q 1303 -91 875 529 \n",
       "Q 447 1150 447 2328 \n",
       "Q 447 3434 972 4092 \n",
       "Q 1497 4750 2381 4750 \n",
       "Q 2619 4750 2861 4703 \n",
       "Q 3103 4656 3366 4563 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-32\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-31\" x=\"127.246094\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-36\" x=\"190.869141\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_6\">\n",
       "     <g id=\"line2d_11\">\n",
       "      <path d=\"M 781.905691 339.84 \n",
       "L 781.905691 7.2 \n",
       "\" clip-path=\"url(#p8d3d213286)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_12\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m13cda5a59d\" x=\"781.905691\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_6\">\n",
       "      <!-- 2020 -->\n",
       "      <g transform=\"translate(769.180691 354.438437) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSans-32\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-32\" x=\"127.246094\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"190.869141\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"xtick_7\">\n",
       "     <g id=\"line2d_13\">\n",
       "      <path d=\"M 926.143043 339.84 \n",
       "L 926.143043 7.2 \n",
       "\" clip-path=\"url(#p8d3d213286)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_14\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#m13cda5a59d\" x=\"926.143043\" y=\"339.84\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_7\">\n",
       "      <!-- 2024 -->\n",
       "      <g transform=\"translate(913.418043 354.438437) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSans-32\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-30\" x=\"63.623047\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-32\" x=\"127.246094\"/>\n",
       "       <use xlink:href=\"#DejaVuSans-34\" x=\"190.869141\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"matplotlib.axis_2\">\n",
       "    <g id=\"ytick_1\">\n",
       "     <g id=\"line2d_15\">\n",
       "      <path d=\"M 20.5625 336.164821 \n",
       "L 969.1625 336.164821 \n",
       "\" clip-path=\"url(#p8d3d213286)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_16\">\n",
       "      <defs>\n",
       "       <path id=\"mf271c4c2e9\" d=\"M 0 0 \n",
       "L -3.5 0 \n",
       "\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </defs>\n",
       "      <g>\n",
       "       <use xlink:href=\"#mf271c4c2e9\" x=\"20.5625\" y=\"336.164821\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_8\">\n",
       "      <!-- 0 -->\n",
       "      <g transform=\"translate(7.2 339.96404) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSans-30\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_2\">\n",
       "     <g id=\"line2d_17\">\n",
       "      <path d=\"M 20.5625 297.219303 \n",
       "L 969.1625 297.219303 \n",
       "\" clip-path=\"url(#p8d3d213286)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_18\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mf271c4c2e9\" x=\"20.5625\" y=\"297.219303\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_9\">\n",
       "      <!-- 1 -->\n",
       "      <g transform=\"translate(7.2 301.018521) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSans-31\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_3\">\n",
       "     <g id=\"line2d_19\">\n",
       "      <path d=\"M 20.5625 258.273784 \n",
       "L 969.1625 258.273784 \n",
       "\" clip-path=\"url(#p8d3d213286)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_20\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mf271c4c2e9\" x=\"20.5625\" y=\"258.273784\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_10\">\n",
       "      <!-- 2 -->\n",
       "      <g transform=\"translate(7.2 262.073003) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSans-32\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_4\">\n",
       "     <g id=\"line2d_21\">\n",
       "      <path d=\"M 20.5625 219.328266 \n",
       "L 969.1625 219.328266 \n",
       "\" clip-path=\"url(#p8d3d213286)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_22\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mf271c4c2e9\" x=\"20.5625\" y=\"219.328266\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_11\">\n",
       "      <!-- 3 -->\n",
       "      <g transform=\"translate(7.2 223.127485) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-33\" d=\"M 2597 2516 \n",
       "Q 3050 2419 3304 2112 \n",
       "Q 3559 1806 3559 1356 \n",
       "Q 3559 666 3084 287 \n",
       "Q 2609 -91 1734 -91 \n",
       "Q 1441 -91 1130 -33 \n",
       "Q 819 25 488 141 \n",
       "L 488 750 \n",
       "Q 750 597 1062 519 \n",
       "Q 1375 441 1716 441 \n",
       "Q 2309 441 2620 675 \n",
       "Q 2931 909 2931 1356 \n",
       "Q 2931 1769 2642 2001 \n",
       "Q 2353 2234 1838 2234 \n",
       "L 1294 2234 \n",
       "L 1294 2753 \n",
       "L 1863 2753 \n",
       "Q 2328 2753 2575 2939 \n",
       "Q 2822 3125 2822 3475 \n",
       "Q 2822 3834 2567 4026 \n",
       "Q 2313 4219 1838 4219 \n",
       "Q 1578 4219 1281 4162 \n",
       "Q 984 4106 628 3988 \n",
       "L 628 4550 \n",
       "Q 988 4650 1302 4700 \n",
       "Q 1616 4750 1894 4750 \n",
       "Q 2613 4750 3031 4423 \n",
       "Q 3450 4097 3450 3541 \n",
       "Q 3450 3153 3228 2886 \n",
       "Q 3006 2619 2597 2516 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-33\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_5\">\n",
       "     <g id=\"line2d_23\">\n",
       "      <path d=\"M 20.5625 180.382747 \n",
       "L 969.1625 180.382747 \n",
       "\" clip-path=\"url(#p8d3d213286)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_24\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mf271c4c2e9\" x=\"20.5625\" y=\"180.382747\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_12\">\n",
       "      <!-- 4 -->\n",
       "      <g transform=\"translate(7.2 184.181966) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSans-34\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_6\">\n",
       "     <g id=\"line2d_25\">\n",
       "      <path d=\"M 20.5625 141.437229 \n",
       "L 969.1625 141.437229 \n",
       "\" clip-path=\"url(#p8d3d213286)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_26\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mf271c4c2e9\" x=\"20.5625\" y=\"141.437229\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_13\">\n",
       "      <!-- 5 -->\n",
       "      <g transform=\"translate(7.2 145.236448) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-35\" d=\"M 691 4666 \n",
       "L 3169 4666 \n",
       "L 3169 4134 \n",
       "L 1269 4134 \n",
       "L 1269 2991 \n",
       "Q 1406 3038 1543 3061 \n",
       "Q 1681 3084 1819 3084 \n",
       "Q 2600 3084 3056 2656 \n",
       "Q 3513 2228 3513 1497 \n",
       "Q 3513 744 3044 326 \n",
       "Q 2575 -91 1722 -91 \n",
       "Q 1428 -91 1123 -41 \n",
       "Q 819 9 494 109 \n",
       "L 494 744 \n",
       "Q 775 591 1075 516 \n",
       "Q 1375 441 1709 441 \n",
       "Q 2250 441 2565 725 \n",
       "Q 2881 1009 2881 1497 \n",
       "Q 2881 1984 2565 2268 \n",
       "Q 2250 2553 1709 2553 \n",
       "Q 1456 2553 1204 2497 \n",
       "Q 953 2441 691 2322 \n",
       "L 691 4666 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-35\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_7\">\n",
       "     <g id=\"line2d_27\">\n",
       "      <path d=\"M 20.5625 102.491711 \n",
       "L 969.1625 102.491711 \n",
       "\" clip-path=\"url(#p8d3d213286)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_28\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mf271c4c2e9\" x=\"20.5625\" y=\"102.491711\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_14\">\n",
       "      <!-- 6 -->\n",
       "      <g transform=\"translate(7.2 106.290929) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSans-36\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_8\">\n",
       "     <g id=\"line2d_29\">\n",
       "      <path d=\"M 20.5625 63.546192 \n",
       "L 969.1625 63.546192 \n",
       "\" clip-path=\"url(#p8d3d213286)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_30\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mf271c4c2e9\" x=\"20.5625\" y=\"63.546192\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_15\">\n",
       "      <!-- 7 -->\n",
       "      <g transform=\"translate(7.2 67.345411) scale(0.1 -0.1)\">\n",
       "       <defs>\n",
       "        <path id=\"DejaVuSans-37\" d=\"M 525 4666 \n",
       "L 3525 4666 \n",
       "L 3525 4397 \n",
       "L 1831 0 \n",
       "L 1172 0 \n",
       "L 2766 4134 \n",
       "L 525 4134 \n",
       "L 525 4666 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       </defs>\n",
       "       <use xlink:href=\"#DejaVuSans-37\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"ytick_9\">\n",
       "     <g id=\"line2d_31\">\n",
       "      <path d=\"M 20.5625 24.600674 \n",
       "L 969.1625 24.600674 \n",
       "\" clip-path=\"url(#p8d3d213286)\" style=\"fill: none; stroke: #b0b0b0; stroke-width: 0.8; stroke-linecap: square\"/>\n",
       "     </g>\n",
       "     <g id=\"line2d_32\">\n",
       "      <g>\n",
       "       <use xlink:href=\"#mf271c4c2e9\" x=\"20.5625\" y=\"24.600674\" style=\"stroke: #000000; stroke-width: 0.8\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "     <g id=\"text_16\">\n",
       "      <!-- 8 -->\n",
       "      <g transform=\"translate(7.2 28.399892) scale(0.1 -0.1)\">\n",
       "       <use xlink:href=\"#DejaVuSans-38\"/>\n",
       "      </g>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "   <g id=\"line2d_33\">\n",
       "    <path d=\"M 63.680682 303.015002 \n",
       "L 66.543709 302.26991 \n",
       "L 69.604187 299.783162 \n",
       "L 72.56594 299.422222 \n",
       "L 75.626417 300.043972 \n",
       "L 78.58817 300.037472 \n",
       "L 81.648648 300.512036 \n",
       "L 84.709125 300.799135 \n",
       "L 87.670878 302.481695 \n",
       "L 90.731356 303.207609 \n",
       "L 93.693108 302.103814 \n",
       "L 96.753586 302.488767 \n",
       "L 99.814064 302.363819 \n",
       "L 102.578366 303.243965 \n",
       "L 105.638844 301.757574 \n",
       "L 108.600596 302.587097 \n",
       "L 111.661074 304.011245 \n",
       "L 114.622827 302.99638 \n",
       "L 117.683304 303.205635 \n",
       "L 120.743782 303.932245 \n",
       "L 123.705535 303.873185 \n",
       "L 126.766013 303.518495 \n",
       "L 129.727765 301.455919 \n",
       "L 132.788243 300.449721 \n",
       "L 135.848721 302.580101 \n",
       "L 138.613023 300.073914 \n",
       "L 141.673501 301.128359 \n",
       "L 144.635253 301.55118 \n",
       "L 147.695731 301.775641 \n",
       "L 150.657484 298.805538 \n",
       "L 153.717961 296.867414 \n",
       "L 156.778439 297.06338 \n",
       "L 159.740192 298.376775 \n",
       "L 165.762422 298.571302 \n",
       "L 168.8229 298.924315 \n",
       "L 171.883377 294.908685 \n",
       "L 177.708157 293.073676 \n",
       "L 180.66991 299.333418 \n",
       "L 186.69214 296.599006 \n",
       "L 189.752618 297.936129 \n",
       "L 192.813096 296.369009 \n",
       "L 195.774848 296.479474 \n",
       "L 198.835326 296.154417 \n",
       "L 201.797079 295.957525 \n",
       "L 204.857556 296.9356 \n",
       "L 207.918034 294.957604 \n",
       "L 210.781062 295.76292 \n",
       "L 213.841539 296.075249 \n",
       "L 216.803292 299.085743 \n",
       "L 219.86377 299.334377 \n",
       "L 222.825522 297.494548 \n",
       "L 225.886 296.948538 \n",
       "L 228.946478 297.352572 \n",
       "L 231.90823 294.500806 \n",
       "L 234.968708 298.231854 \n",
       "L 237.930461 295.671585 \n",
       "L 240.990938 295.106527 \n",
       "L 244.051416 296.63623 \n",
       "L 246.815719 294.717983 \n",
       "L 249.876196 291.720011 \n",
       "L 252.837949 297.473901 \n",
       "L 255.898427 293.064726 \n",
       "L 258.860179 292.278177 \n",
       "L 261.920657 295.201609 \n",
       "L 264.981135 288.933083 \n",
       "L 267.942887 290.304821 \n",
       "L 271.003365 291.382758 \n",
       "L 273.965117 289.870713 \n",
       "L 277.025595 288.035438 \n",
       "L 280.086073 290.992283 \n",
       "L 282.850375 287.178842 \n",
       "L 285.910853 286.130073 \n",
       "L 288.872606 294.250512 \n",
       "L 291.933083 292.352684 \n",
       "L 294.894836 291.385681 \n",
       "L 297.955314 290.537141 \n",
       "L 301.015791 289.895307 \n",
       "L 307.038022 290.631425 \n",
       "L 309.999774 292.984605 \n",
       "L 313.060252 300.995731 \n",
       "L 316.12073 295.810047 \n",
       "L 321.94551 300.503961 \n",
       "L 324.907262 303.094273 \n",
       "L 327.96774 299.255319 \n",
       "L 330.929493 299.619203 \n",
       "L 333.98997 294.038697 \n",
       "L 337.050448 297.232389 \n",
       "L 340.012201 299.98595 \n",
       "L 343.072678 300.582361 \n",
       "L 346.034431 295.900483 \n",
       "L 349.094909 297.460882 \n",
       "L 352.155387 300.012723 \n",
       "L 355.018414 301.267807 \n",
       "L 358.078892 300.482235 \n",
       "L 361.040644 297.966652 \n",
       "L 364.101122 296.436042 \n",
       "L 367.062875 296.58836 \n",
       "L 370.123352 290.443968 \n",
       "L 373.18383 289.264876 \n",
       "L 376.145583 284.96386 \n",
       "L 379.20606 286.032217 \n",
       "L 382.167813 284.584152 \n",
       "L 385.228291 279.818336 \n",
       "L 388.288768 277.101145 \n",
       "L 391.053071 274.321989 \n",
       "L 394.113549 269.817917 \n",
       "L 397.075301 270.893477 \n",
       "L 400.135779 269.255542 \n",
       "L 403.097531 273.221796 \n",
       "L 406.158009 273.758014 \n",
       "L 409.218487 265.702001 \n",
       "L 412.18024 262.959111 \n",
       "L 415.240717 263.658552 \n",
       "L 418.20247 263.683439 \n",
       "L 421.262948 262.312278 \n",
       "L 424.323425 259.093116 \n",
       "L 427.087728 261.966843 \n",
       "L 430.148205 260.334389 \n",
       "L 433.109958 260.929441 \n",
       "L 436.170436 267.830715 \n",
       "L 439.132188 267.187484 \n",
       "L 442.192666 260.177915 \n",
       "L 445.253144 265.353068 \n",
       "L 448.214896 270.001522 \n",
       "L 451.275374 269.305884 \n",
       "L 454.237127 256.956936 \n",
       "L 457.297604 251.962017 \n",
       "L 460.358082 250.341373 \n",
       "L 463.122384 240.81014 \n",
       "L 466.182862 238.85091 \n",
       "L 469.144615 241.848794 \n",
       "L 472.205092 242.967013 \n",
       "L 475.166845 240.177469 \n",
       "L 478.227323 237.056821 \n",
       "L 481.287801 241.285338 \n",
       "L 484.249553 239.913176 \n",
       "L 487.310031 235.029963 \n",
       "L 490.271783 234.982894 \n",
       "L 493.332261 224.772742 \n",
       "L 496.392739 224.013459 \n",
       "L 499.255766 215.367973 \n",
       "L 502.316244 210.138102 \n",
       "L 505.277997 206.710483 \n",
       "L 508.338474 207.026923 \n",
       "L 511.300227 206.721247 \n",
       "L 514.360705 210.5792 \n",
       "L 517.421182 201.728259 \n",
       "L 520.382935 188.504369 \n",
       "L 523.443413 182.056676 \n",
       "L 526.405165 186.933778 \n",
       "L 529.465643 177.804073 \n",
       "L 532.526121 181.416939 \n",
       "L 535.290423 188.202884 \n",
       "L 538.350901 198.7012 \n",
       "L 541.312654 195.928577 \n",
       "L 544.373131 193.726444 \n",
       "L 547.334884 197.370374 \n",
       "L 550.395362 191.397703 \n",
       "L 553.455839 185.932922 \n",
       "L 556.417592 189.240599 \n",
       "L 559.47807 175.854383 \n",
       "L 562.439822 171.202005 \n",
       "L 565.5003 171.118102 \n",
       "L 568.560778 171.870925 \n",
       "L 571.32508 169.019526 \n",
       "L 574.385558 159.4564 \n",
       "L 577.34731 160.264468 \n",
       "L 580.407788 157.213499 \n",
       "L 583.369541 160.112043 \n",
       "L 589.490496 135.115129 \n",
       "L 592.452249 151.489697 \n",
       "L 595.512726 153.191535 \n",
       "L 598.474479 172.122716 \n",
       "L 601.534957 229.380214 \n",
       "L 604.595434 207.879393 \n",
       "L 607.359737 217.121011 \n",
       "L 610.420215 229.674032 \n",
       "L 613.381967 239.011325 \n",
       "L 616.442445 223.500532 \n",
       "L 619.404197 193.453598 \n",
       "L 622.464675 183.466568 \n",
       "L 625.525153 177.01748 \n",
       "L 628.486905 159.786578 \n",
       "L 631.547383 153.884831 \n",
       "L 634.509136 163.185513 \n",
       "L 637.569613 155.278611 \n",
       "L 640.630091 148.235369 \n",
       "L 643.493119 150.150115 \n",
       "L 646.553596 124.32433 \n",
       "L 649.515349 117.037366 \n",
       "L 652.575827 113.185376 \n",
       "L 655.537579 113.271539 \n",
       "L 658.598057 99.613994 \n",
       "L 661.658535 80.662598 \n",
       "L 664.620287 83.415197 \n",
       "L 667.680765 71.670065 \n",
       "L 670.642518 88.90915 \n",
       "L 673.702995 82.589459 \n",
       "L 676.763473 78.114697 \n",
       "L 679.527776 62.020617 \n",
       "L 682.588253 65.008993 \n",
       "L 685.550006 85.749719 \n",
       "L 688.610484 111.392361 \n",
       "L 691.572236 103.637465 \n",
       "L 694.632714 116.291909 \n",
       "L 697.693192 103.577268 \n",
       "L 700.654944 102.704012 \n",
       "L 703.715422 108.131695 \n",
       "L 706.677175 110.927992 \n",
       "L 709.737652 110.912369 \n",
       "L 712.79813 114.922271 \n",
       "L 715.562432 98.248979 \n",
       "L 718.62291 100.350918 \n",
       "L 721.584663 100.041026 \n",
       "L 724.64514 111.277076 \n",
       "L 727.606893 114.963186 \n",
       "L 730.667371 114.044567 \n",
       "L 733.727848 126.810189 \n",
       "L 736.689601 134.073155 \n",
       "L 739.750079 134.292336 \n",
       "L 742.711831 123.307423 \n",
       "L 745.772309 119.674108 \n",
       "L 748.832787 117.961219 \n",
       "L 751.597089 75.318374 \n",
       "L 754.657567 90.400281 \n",
       "L 757.619319 83.134426 \n",
       "L 760.679797 81.945109 \n",
       "L 763.64155 67.162914 \n",
       "L 766.702028 63.567795 \n",
       "L 769.762505 75.928528 \n",
       "L 772.724258 70.757577 \n",
       "L 775.784736 68.995428 \n",
       "L 778.746488 61.521921 \n",
       "L 781.806966 74.502515 \n",
       "L 784.867444 80.447163 \n",
       "L 787.730471 101.771569 \n",
       "L 790.790949 88.145296 \n",
       "L 793.752701 62.610986 \n",
       "L 796.813179 74.702154 \n",
       "L 799.774932 75.899176 \n",
       "L 802.835409 89.875904 \n",
       "L 805.895887 85.841783 \n",
       "L 808.85764 82.302481 \n",
       "L 811.918117 95.359216 \n",
       "L 814.87987 101.964798 \n",
       "L 817.940348 105.410908 \n",
       "L 821.000825 132.1597 \n",
       "L 823.765128 119.935939 \n",
       "L 826.825606 116.763743 \n",
       "L 829.787358 109.205771 \n",
       "L 832.847836 116.142722 \n",
       "L 835.809589 127.159019 \n",
       "L 838.870066 157.149011 \n",
       "L 841.930544 183.501021 \n",
       "L 844.892297 162.683095 \n",
       "L 847.952774 150.40775 \n",
       "L 850.914527 150.911491 \n",
       "L 853.975005 135.241189 \n",
       "L 857.035482 136.033761 \n",
       "L 859.799785 128.770681 \n",
       "L 862.860262 130.573237 \n",
       "L 865.822015 128.203546 \n",
       "L 868.882493 108.953096 \n",
       "L 871.844245 119.381317 \n",
       "L 874.904723 114.860318 \n",
       "L 877.965201 94.968482 \n",
       "L 880.926953 108.07152 \n",
       "L 883.987431 88.57453 \n",
       "L 886.949184 45.069346 \n",
       "L 890.009661 51.16381 \n",
       "L 893.070139 37.291571 \n",
       "L 895.834442 22.32 \n",
       "L 898.894919 49.369687 \n",
       "L 901.856672 84.661695 \n",
       "L 904.91715 80.522376 \n",
       "L 907.878902 90.524723 \n",
       "L 910.93938 71.076056 \n",
       "L 913.999858 65.634853 \n",
       "L 916.96161 65.726941 \n",
       "L 920.022088 86.420463 \n",
       "L 922.98384 86.348312 \n",
       "L 926.044318 79.779778 \n",
       "L 926.044318 79.779778 \n",
       "\" clip-path=\"url(#p8d3d213286)\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_34\">\n",
       "    <path d=\"M 63.680682 286.403836 \n",
       "L 66.543709 280.134781 \n",
       "L 69.604187 282.646518 \n",
       "L 72.56594 283.487498 \n",
       "L 75.626417 281.550155 \n",
       "L 78.58817 281.709092 \n",
       "L 81.648648 279.360283 \n",
       "L 84.709125 278.640804 \n",
       "L 87.670878 279.495166 \n",
       "L 90.731356 277.372587 \n",
       "L 93.693108 275.765139 \n",
       "L 96.753586 275.989466 \n",
       "L 99.814064 277.73399 \n",
       "L 102.578366 280.337182 \n",
       "L 105.638844 277.012206 \n",
       "L 108.600596 275.572453 \n",
       "L 111.661074 271.865519 \n",
       "L 114.622827 274.173369 \n",
       "L 117.683304 282.288441 \n",
       "L 120.743782 283.355585 \n",
       "L 123.705535 286.101486 \n",
       "L 126.766013 287.436868 \n",
       "L 129.727765 287.796559 \n",
       "L 135.848721 295.830119 \n",
       "L 138.613023 295.461964 \n",
       "L 141.673501 292.271468 \n",
       "L 144.635253 290.992403 \n",
       "L 147.695731 294.943326 \n",
       "L 150.657484 291.68331 \n",
       "L 153.717961 294.607123 \n",
       "L 156.778439 294.279533 \n",
       "L 159.740192 295.891192 \n",
       "L 162.800669 297.379206 \n",
       "L 165.762422 299.362779 \n",
       "L 168.8229 300.546032 \n",
       "L 171.883377 299.626172 \n",
       "L 174.64768 300.046906 \n",
       "L 177.708157 300.925992 \n",
       "L 180.66991 298.734527 \n",
       "L 183.730388 297.354131 \n",
       "L 186.69214 300.958611 \n",
       "L 189.752618 300.602264 \n",
       "L 195.774848 304.017385 \n",
       "L 198.835326 306.37138 \n",
       "L 201.797079 305.031834 \n",
       "L 204.857556 304.542777 \n",
       "L 207.918034 303.4413 \n",
       "L 210.781062 301.458707 \n",
       "L 213.841539 300.756859 \n",
       "L 216.803292 303.868012 \n",
       "L 219.86377 304.858324 \n",
       "L 222.825522 310.025662 \n",
       "L 225.886 310.073038 \n",
       "L 228.946478 311.699553 \n",
       "L 231.90823 311.502964 \n",
       "L 234.968708 311.669053 \n",
       "L 237.930461 312.047828 \n",
       "L 240.990938 314.01776 \n",
       "L 244.051416 314.859848 \n",
       "L 246.815719 313.215018 \n",
       "L 249.876196 316.047197 \n",
       "L 252.837949 315.351583 \n",
       "L 255.898427 318.005028 \n",
       "L 258.860179 317.939697 \n",
       "L 261.920657 317.676669 \n",
       "L 264.981135 317.132526 \n",
       "L 267.942887 316.865212 \n",
       "L 273.965117 318.113829 \n",
       "L 277.025595 317.411577 \n",
       "L 280.086073 315.400127 \n",
       "L 282.850375 315.71125 \n",
       "L 285.910853 314.94191 \n",
       "L 288.872606 310.947171 \n",
       "L 291.933083 305.662282 \n",
       "L 294.894836 305.368881 \n",
       "L 297.955314 307.585453 \n",
       "L 301.015791 306.3377 \n",
       "L 303.977544 304.216539 \n",
       "L 307.038022 303.813763 \n",
       "L 309.999774 298.239168 \n",
       "L 313.060252 289.840042 \n",
       "L 316.12073 284.83133 \n",
       "L 318.885032 280.061733 \n",
       "L 321.94551 271.699247 \n",
       "L 324.907262 250.743195 \n",
       "L 327.96774 245.949934 \n",
       "L 330.929493 256.447023 \n",
       "L 333.98997 243.499257 \n",
       "L 337.050448 228.185731 \n",
       "L 340.012201 222.539196 \n",
       "L 343.072678 227.704963 \n",
       "L 346.034431 247.985016 \n",
       "L 349.094909 232.776297 \n",
       "L 352.155387 242.58451 \n",
       "L 355.018414 238.211528 \n",
       "L 358.078892 256.304037 \n",
       "L 361.040644 258.044042 \n",
       "L 364.101122 266.606364 \n",
       "L 367.062875 281.412977 \n",
       "L 370.123352 283.971943 \n",
       "L 373.18383 294.919375 \n",
       "L 376.145583 300.324407 \n",
       "L 379.20606 309.835682 \n",
       "L 382.167813 306.221131 \n",
       "L 385.228291 307.345178 \n",
       "L 388.288768 305.053254 \n",
       "L 391.053071 304.455405 \n",
       "L 394.113549 298.315119 \n",
       "L 400.135779 293.923251 \n",
       "L 403.097531 289.186815 \n",
       "L 406.158009 283.00529 \n",
       "L 409.218487 297.55526 \n",
       "L 412.18024 296.451964 \n",
       "L 415.240717 292.40489 \n",
       "L 418.20247 288.995545 \n",
       "L 421.262948 289.172823 \n",
       "L 424.323425 295.858993 \n",
       "L 427.087728 293.34548 \n",
       "L 430.148205 293.298866 \n",
       "L 433.109958 295.553879 \n",
       "L 436.170436 296.269456 \n",
       "L 439.132188 300.769087 \n",
       "L 442.192666 298.621291 \n",
       "L 445.253144 295.802641 \n",
       "L 448.214896 294.060601 \n",
       "L 451.275374 289.608035 \n",
       "L 454.237127 294.410655 \n",
       "L 457.297604 296.354614 \n",
       "L 460.358082 298.600129 \n",
       "L 463.122384 298.353482 \n",
       "L 466.182862 298.639791 \n",
       "L 469.144615 299.422948 \n",
       "L 472.205092 302.11098 \n",
       "L 475.166845 300.99529 \n",
       "L 478.227323 301.998712 \n",
       "L 481.287801 303.176494 \n",
       "L 484.249553 307.65969 \n",
       "L 487.310031 307.238766 \n",
       "L 490.271783 309.457445 \n",
       "L 493.332261 314.502693 \n",
       "L 496.392739 313.651397 \n",
       "L 499.255766 311.89582 \n",
       "L 502.316244 314.5942 \n",
       "L 505.277997 313.499862 \n",
       "L 508.338474 313.375011 \n",
       "L 511.300227 314.578645 \n",
       "L 517.421182 316.666348 \n",
       "L 520.382935 317.21021 \n",
       "L 523.443413 318.047022 \n",
       "L 526.405165 319.400071 \n",
       "L 529.465643 316.989253 \n",
       "L 532.526121 315.879643 \n",
       "L 535.290423 315.2108 \n",
       "L 538.350901 315.063978 \n",
       "L 541.312654 315.669037 \n",
       "L 544.373131 313.078642 \n",
       "L 547.334884 316.052546 \n",
       "L 550.395362 316.104469 \n",
       "L 553.455839 315.469255 \n",
       "L 556.417592 313.760584 \n",
       "L 559.47807 316.435633 \n",
       "L 562.439822 315.572319 \n",
       "L 565.5003 316.824147 \n",
       "L 568.560778 316.610431 \n",
       "L 571.32508 316.993582 \n",
       "L 574.385558 318.729961 \n",
       "L 577.34731 318.95059 \n",
       "L 580.407788 318.78996 \n",
       "L 583.369541 318.113669 \n",
       "L 586.430018 317.702913 \n",
       "L 589.490496 317.849887 \n",
       "L 592.452249 315.781601 \n",
       "L 595.512726 315.426992 \n",
       "L 598.474479 312.571998 \n",
       "L 601.534957 305.298789 \n",
       "L 604.595434 306.811693 \n",
       "L 607.359737 303.97807 \n",
       "L 610.420215 297.279405 \n",
       "L 613.381967 288.131291 \n",
       "L 616.442445 285.405281 \n",
       "L 619.404197 299.627082 \n",
       "L 622.464675 307.606597 \n",
       "L 625.525153 312.949988 \n",
       "L 628.486905 315.576415 \n",
       "L 631.547383 311.858596 \n",
       "L 634.509136 310.483926 \n",
       "L 637.569613 310.986466 \n",
       "L 640.630091 319.625938 \n",
       "L 643.493119 319.842491 \n",
       "L 646.553596 318.323023 \n",
       "L 649.515349 319.105612 \n",
       "L 652.575827 319.584083 \n",
       "L 655.537579 318.838031 \n",
       "L 658.598057 319.94516 \n",
       "L 661.658535 319.836975 \n",
       "L 664.620287 320.093348 \n",
       "L 667.680765 319.852668 \n",
       "L 670.642518 318.425885 \n",
       "L 673.702995 319.905883 \n",
       "L 676.763473 320.601363 \n",
       "L 679.527776 320.610649 \n",
       "L 682.588253 320.85516 \n",
       "L 685.550006 320.840556 \n",
       "L 688.610484 321.031497 \n",
       "L 694.632714 319.886571 \n",
       "L 697.693192 319.511814 \n",
       "L 700.654944 319.58824 \n",
       "L 703.715422 319.339457 \n",
       "L 706.677175 319.767746 \n",
       "L 709.737652 319.976927 \n",
       "L 712.79813 319.5143 \n",
       "L 715.562432 320.829939 \n",
       "L 718.62291 320.850249 \n",
       "L 721.584663 321.357925 \n",
       "L 724.64514 321.10767 \n",
       "L 727.606893 322.306653 \n",
       "L 730.667371 322.224308 \n",
       "L 733.727848 322.900643 \n",
       "L 736.689601 322.265056 \n",
       "L 739.750079 323.994542 \n",
       "L 742.711831 323.994503 \n",
       "L 745.772309 324.67026 \n",
       "L 748.832787 324.72 \n",
       "L 751.597089 323.191174 \n",
       "L 754.657567 322.146173 \n",
       "L 757.619319 322.598545 \n",
       "L 760.679797 323.602867 \n",
       "L 763.64155 323.899778 \n",
       "L 766.702028 323.983403 \n",
       "L 769.762505 323.692919 \n",
       "L 775.784736 323.747448 \n",
       "L 778.746488 324.070547 \n",
       "L 781.806966 322.599023 \n",
       "L 784.867444 322.297001 \n",
       "L 787.730471 321.287704 \n",
       "L 790.790949 322.984739 \n",
       "L 793.752701 322.759142 \n",
       "L 796.813179 322.167612 \n",
       "L 799.774932 320.84389 \n",
       "L 802.835409 318.342964 \n",
       "L 805.895887 318.436949 \n",
       "L 808.85764 319.653922 \n",
       "L 811.918117 319.233088 \n",
       "L 814.87987 318.518785 \n",
       "L 817.940348 317.575541 \n",
       "L 821.000825 317.008528 \n",
       "L 823.765128 317.681605 \n",
       "L 826.825606 318.669403 \n",
       "L 829.787358 318.691985 \n",
       "L 832.847836 317.076239 \n",
       "L 835.809589 316.271867 \n",
       "L 838.870066 315.061979 \n",
       "L 841.930544 312.919619 \n",
       "L 844.892297 315.128222 \n",
       "L 847.952774 315.932046 \n",
       "L 850.914527 315.693235 \n",
       "L 853.975005 316.886243 \n",
       "L 857.035482 319.119391 \n",
       "L 859.799785 318.539204 \n",
       "L 862.860262 319.888112 \n",
       "L 865.822015 321.529069 \n",
       "L 868.882493 321.376245 \n",
       "L 871.844245 319.54487 \n",
       "L 874.904723 320.074904 \n",
       "L 877.965201 321.815168 \n",
       "L 880.926953 322.39402 \n",
       "L 883.987431 323.471505 \n",
       "L 890.009661 323.840487 \n",
       "L 893.070139 323.328957 \n",
       "L 895.834442 323.707736 \n",
       "L 898.894919 323.214889 \n",
       "L 901.856672 322.345724 \n",
       "L 904.91715 322.83523 \n",
       "L 907.878902 322.182338 \n",
       "L 910.93938 322.937125 \n",
       "L 913.999858 323.850383 \n",
       "L 916.96161 324.008924 \n",
       "L 922.98384 323.846459 \n",
       "L 926.044318 324.463063 \n",
       "L 926.044318 324.463063 \n",
       "\" clip-path=\"url(#p8d3d213286)\" style=\"fill: none; stroke: #ff7f0e; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_35\">\n",
       "    <path d=\"M 63.680682 292.199535 \n",
       "L 66.543709 285.672456 \n",
       "L 69.604187 284.231505 \n",
       "L 72.56594 284.532351 \n",
       "L 75.626417 283.507149 \n",
       "L 78.58817 283.650913 \n",
       "L 81.648648 282.075677 \n",
       "L 84.709125 281.82615 \n",
       "L 87.670878 285.218423 \n",
       "L 90.731356 284.40817 \n",
       "L 93.693108 281.25966 \n",
       "L 96.753586 282.084113 \n",
       "L 99.814064 283.451293 \n",
       "L 102.578366 287.172379 \n",
       "L 105.638844 282.042464 \n",
       "L 108.600596 282.029979 \n",
       "L 111.661074 281.014152 \n",
       "L 114.622827 281.252913 \n",
       "L 117.683304 288.78766 \n",
       "L 120.743782 290.770538 \n",
       "L 123.705535 293.047709 \n",
       "L 126.766013 293.724211 \n",
       "L 129.727765 291.356119 \n",
       "L 132.788243 293.813529 \n",
       "L 135.848721 300.142335 \n",
       "L 138.613023 297.12544 \n",
       "L 141.673501 295.205924 \n",
       "L 144.635253 294.506662 \n",
       "L 147.695731 298.42036 \n",
       "L 150.657484 292.175438 \n",
       "L 153.717961 292.784821 \n",
       "L 156.778439 292.659192 \n",
       "L 159.740192 295.794528 \n",
       "L 162.800669 297.42179 \n",
       "L 165.762422 299.472654 \n",
       "L 168.8229 300.996923 \n",
       "L 171.883377 296.296567 \n",
       "L 174.64768 295.868217 \n",
       "L 177.708157 295.973132 \n",
       "L 180.66991 299.3122 \n",
       "L 183.730388 296.541503 \n",
       "L 186.69214 298.850032 \n",
       "L 189.752618 299.733392 \n",
       "L 192.813096 299.991955 \n",
       "L 195.774848 301.91413 \n",
       "L 198.835326 304.141592 \n",
       "L 201.797079 302.544206 \n",
       "L 204.857556 302.833921 \n",
       "L 207.918034 299.992326 \n",
       "L 210.781062 298.507695 \n",
       "L 213.841539 298.03728 \n",
       "L 216.803292 304.250549 \n",
       "L 219.86377 305.443132 \n",
       "L 222.825522 308.979272 \n",
       "L 225.886 308.644694 \n",
       "L 228.946478 310.643782 \n",
       "L 231.90823 308.563527 \n",
       "L 234.968708 311.221132 \n",
       "L 237.930461 309.923269 \n",
       "L 244.051416 313.542211 \n",
       "L 246.815719 310.697823 \n",
       "L 249.876196 311.998539 \n",
       "L 252.837949 314.291536 \n",
       "L 255.898427 314.587469 \n",
       "L 258.860179 314.11607 \n",
       "L 261.920657 315.266598 \n",
       "L 264.981135 311.453504 \n",
       "L 267.942887 311.824111 \n",
       "L 271.003365 313.185715 \n",
       "L 273.965117 313.176041 \n",
       "L 277.025595 311.370327 \n",
       "L 280.086073 310.234158 \n",
       "L 282.850375 308.433633 \n",
       "L 285.910853 306.796839 \n",
       "L 288.872606 306.035279 \n",
       "L 291.933083 298.356771 \n",
       "L 294.894836 297.158616 \n",
       "L 297.955314 299.226984 \n",
       "L 301.015791 297.094711 \n",
       "L 303.977544 294.590646 \n",
       "L 307.038022 294.438545 \n",
       "L 309.999774 289.40488 \n",
       "L 313.060252 287.724552 \n",
       "L 316.12073 275.344589 \n",
       "L 318.885032 273.063309 \n",
       "L 321.94551 267.726678 \n",
       "L 324.907262 250.450419 \n",
       "L 327.96774 235.690676 \n",
       "L 330.929493 248.372055 \n",
       "L 333.98997 220.706819 \n",
       "L 337.050448 210.379884 \n",
       "L 340.012201 212.698581 \n",
       "L 343.072678 220.347079 \n",
       "L 346.034431 226.763827 \n",
       "L 349.094909 212.134719 \n",
       "L 352.155387 232.078741 \n",
       "L 355.018414 230.828361 \n",
       "L 358.078892 247.913336 \n",
       "L 361.040644 243.614524 \n",
       "L 364.101122 250.049862 \n",
       "L 367.062875 268.710947 \n",
       "L 370.123352 261.391111 \n",
       "L 373.18383 275.146527 \n",
       "L 376.145583 277.546947 \n",
       "L 379.20606 294.325988 \n",
       "L 382.167813 287.373714 \n",
       "L 385.228291 284.697194 \n",
       "L 388.288768 278.122237 \n",
       "L 391.053071 274.275765 \n",
       "L 394.113549 257.783983 \n",
       "L 397.075301 254.512535 \n",
       "L 400.135779 247.980514 \n",
       "L 403.097531 243.320036 \n",
       "L 406.158009 231.89416 \n",
       "L 409.218487 246.973283 \n",
       "L 412.18024 240.952631 \n",
       "L 415.240717 232.159408 \n",
       "L 418.20247 224.092025 \n",
       "L 421.262948 222.393105 \n",
       "L 424.323425 233.621704 \n",
       "L 427.087728 231.050472 \n",
       "L 430.148205 228.623387 \n",
       "L 433.109958 235.124622 \n",
       "L 436.170436 246.173308 \n",
       "L 439.132188 255.475981 \n",
       "L 442.192666 242.380113 \n",
       "L 445.253144 241.726341 \n",
       "L 448.214896 243.84979 \n",
       "L 451.275374 233.116781 \n",
       "L 454.237127 224.713694 \n",
       "L 457.297604 222.874346 \n",
       "L 460.358082 227.084059 \n",
       "L 463.122384 214.253739 \n",
       "L 466.182862 212.671976 \n",
       "L 469.144615 219.053666 \n",
       "L 472.205092 229.009986 \n",
       "L 475.166845 222.292025 \n",
       "L 478.227323 221.838807 \n",
       "L 481.287801 230.657686 \n",
       "L 484.249553 243.470507 \n",
       "L 487.310031 237.398993 \n",
       "L 493.332261 252.95729 \n",
       "L 496.392739 249.120163 \n",
       "L 499.255766 235.62243 \n",
       "L 502.316244 242.448405 \n",
       "L 505.277997 235.145051 \n",
       "L 508.338474 234.835511 \n",
       "L 511.300227 239.947325 \n",
       "L 514.360705 247.653754 \n",
       "L 517.421182 245.742453 \n",
       "L 520.382935 239.370143 \n",
       "L 523.443413 239.416847 \n",
       "L 526.405165 249.703861 \n",
       "L 529.465643 231.980995 \n",
       "L 532.526121 228.329175 \n",
       "L 535.290423 229.502388 \n",
       "L 538.350901 236.323019 \n",
       "L 541.312654 237.172148 \n",
       "L 544.373131 223.106308 \n",
       "L 547.334884 240.562542 \n",
       "L 550.395362 236.69535 \n",
       "L 556.417592 223.350362 \n",
       "L 559.47807 226.541837 \n",
       "L 562.439822 218.563555 \n",
       "L 565.5003 225.652782 \n",
       "L 568.560778 224.935687 \n",
       "L 571.32508 225.184688 \n",
       "L 574.385558 228.886722 \n",
       "L 577.34731 230.734844 \n",
       "L 580.407788 227.922384 \n",
       "L 583.369541 225.462447 \n",
       "L 586.430018 215.123042 \n",
       "L 589.490496 208.021036 \n",
       "L 592.452249 203.986618 \n",
       "L 595.512726 202.905164 \n",
       "L 598.474479 198.346793 \n",
       "L 601.534957 203.964386 \n",
       "L 604.595434 183.825975 \n",
       "L 607.359737 180.094262 \n",
       "L 610.420215 164.070506 \n",
       "L 613.381967 138.673422 \n",
       "L 616.442445 95.935361 \n",
       "L 619.404197 99.174968 \n",
       "L 622.464675 134.346719 \n",
       "L 625.525153 163.584299 \n",
       "L 628.486905 164.424006 \n",
       "L 631.547383 127.664767 \n",
       "L 634.509136 126.511324 \n",
       "L 637.569613 121.030666 \n",
       "L 640.630091 186.473078 \n",
       "L 643.493119 189.958236 \n",
       "L 646.553596 156.048731 \n",
       "L 652.575827 159.621175 \n",
       "L 655.537579 151.745796 \n",
       "L 658.598057 152.229541 \n",
       "L 661.658535 136.266614 \n",
       "L 664.620287 141.55889 \n",
       "L 667.680765 129.601328 \n",
       "L 670.642518 124.997015 \n",
       "L 673.702995 137.217897 \n",
       "L 676.763473 142.217146 \n",
       "L 679.527776 130.236721 \n",
       "L 682.588253 135.718676 \n",
       "L 685.550006 150.859603 \n",
       "L 688.610484 172.143871 \n",
       "L 691.572236 160.708512 \n",
       "L 694.632714 163.403323 \n",
       "L 697.693192 149.4357 \n",
       "L 700.654944 149.591583 \n",
       "L 703.715422 151.129077 \n",
       "L 706.677175 158.108182 \n",
       "L 709.737652 160.367347 \n",
       "L 712.79813 158.472812 \n",
       "L 715.562432 159.121891 \n",
       "L 718.62291 160.920511 \n",
       "L 721.584663 166.499545 \n",
       "L 724.64514 171.705582 \n",
       "L 727.606893 187.496911 \n",
       "L 730.667371 185.996127 \n",
       "L 733.727848 201.912127 \n",
       "L 736.689601 200.136585 \n",
       "L 739.750079 217.209502 \n",
       "L 742.711831 210.736154 \n",
       "L 745.772309 215.559607 \n",
       "L 748.832787 215.127266 \n",
       "L 751.597089 175.304796 \n",
       "L 754.657567 171.648632 \n",
       "L 757.619319 172.093648 \n",
       "L 760.679797 183.468782 \n",
       "L 763.64155 178.199003 \n",
       "L 766.702028 177.164878 \n",
       "L 769.762505 180.583031 \n",
       "L 772.724258 178.294742 \n",
       "L 775.784736 177.121199 \n",
       "L 778.746488 176.810586 \n",
       "L 781.806966 164.95342 \n",
       "L 784.867444 165.031362 \n",
       "L 787.730471 166.847203 \n",
       "L 790.790949 176.318142 \n",
       "L 793.752701 157.125461 \n",
       "L 796.813179 157.13888 \n",
       "L 799.774932 141.02794 \n",
       "L 802.835409 119.653791 \n",
       "L 805.895887 117.249204 \n",
       "L 808.85764 129.18197 \n",
       "L 811.918117 134.55195 \n",
       "L 814.87987 131.576937 \n",
       "L 817.940348 123.651362 \n",
       "L 821.000825 141.803621 \n",
       "L 823.765128 136.986805 \n",
       "L 826.825606 144.709419 \n",
       "L 829.787358 138.361249 \n",
       "L 832.847836 126.115793 \n",
       "L 835.809589 127.781518 \n",
       "L 838.870066 145.008329 \n",
       "L 841.930544 153.741302 \n",
       "L 844.892297 146.197866 \n",
       "L 847.952774 140.01482 \n",
       "L 850.914527 138.231558 \n",
       "L 853.975005 133.023495 \n",
       "L 857.035482 157.355833 \n",
       "L 859.799785 144.780324 \n",
       "L 865.822015 176.722994 \n",
       "L 868.882493 160.298994 \n",
       "L 871.844245 146.591897 \n",
       "L 874.904723 148.684128 \n",
       "L 877.965201 152.110185 \n",
       "L 880.926953 169.533592 \n",
       "L 883.987431 168.32819 \n",
       "L 886.949184 141.412816 \n",
       "L 890.009661 148.204066 \n",
       "L 893.070139 131.253751 \n",
       "L 895.834442 127.035869 \n",
       "L 898.894919 136.786404 \n",
       "L 901.856672 147.939469 \n",
       "L 904.91715 151.508989 \n",
       "L 907.878902 149.689331 \n",
       "L 910.93938 144.991168 \n",
       "L 913.999858 154.266031 \n",
       "L 916.96161 156.669791 \n",
       "L 920.022088 168.921579 \n",
       "L 922.98384 168.026719 \n",
       "L 926.044318 172.022059 \n",
       "L 926.044318 172.022059 \n",
       "\" clip-path=\"url(#p8d3d213286)\" style=\"fill: none; stroke: #2ca02c; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"line2d_36\">\n",
       "    <path d=\"M 63.680682 292.419581 \n",
       "L 66.543709 287.301815 \n",
       "L 69.604187 284.861201 \n",
       "L 72.56594 283.832404 \n",
       "L 75.626417 282.172935 \n",
       "L 78.58817 281.216524 \n",
       "L 81.648648 278.49691 \n",
       "L 84.709125 278.563596 \n",
       "L 87.670878 281.728073 \n",
       "L 90.731356 280.270943 \n",
       "L 93.693108 277.155484 \n",
       "L 96.753586 277.073693 \n",
       "L 99.814064 277.297977 \n",
       "L 102.578366 280.331075 \n",
       "L 105.638844 275.953701 \n",
       "L 108.600596 275.77131 \n",
       "L 111.661074 273.06167 \n",
       "L 114.622827 272.954231 \n",
       "L 117.683304 281.438528 \n",
       "L 120.743782 283.894531 \n",
       "L 126.766013 288.025962 \n",
       "L 129.727765 286.349679 \n",
       "L 132.788243 289.257099 \n",
       "L 135.848721 293.654707 \n",
       "L 138.613023 292.713115 \n",
       "L 141.673501 290.456032 \n",
       "L 144.635253 288.636401 \n",
       "L 147.695731 292.968747 \n",
       "L 150.657484 286.783712 \n",
       "L 153.717961 289.096937 \n",
       "L 156.778439 288.668604 \n",
       "L 159.740192 291.090979 \n",
       "L 168.8229 297.473794 \n",
       "L 171.883377 293.422159 \n",
       "L 174.64768 293.077042 \n",
       "L 177.708157 293.115515 \n",
       "L 180.66991 292.806021 \n",
       "L 183.730388 291.243731 \n",
       "L 186.69214 293.815438 \n",
       "L 189.752618 294.079905 \n",
       "L 195.774848 297.202773 \n",
       "L 198.835326 297.740256 \n",
       "L 201.797079 296.346108 \n",
       "L 204.857556 293.501385 \n",
       "L 210.781062 288.427792 \n",
       "L 213.841539 286.531215 \n",
       "L 216.803292 290.692855 \n",
       "L 219.86377 291.823676 \n",
       "L 222.825522 296.290821 \n",
       "L 225.886 296.660161 \n",
       "L 228.946478 297.918087 \n",
       "L 231.90823 296.360927 \n",
       "L 234.968708 298.531375 \n",
       "L 237.930461 297.95485 \n",
       "L 244.051416 302.199705 \n",
       "L 246.815719 298.945743 \n",
       "L 249.876196 302.50122 \n",
       "L 252.837949 303.130752 \n",
       "L 255.898427 305.935292 \n",
       "L 258.860179 305.359622 \n",
       "L 261.920657 305.30006 \n",
       "L 264.981135 303.026733 \n",
       "L 267.942887 303.231637 \n",
       "L 271.003365 305.02106 \n",
       "L 273.965117 304.837529 \n",
       "L 277.025595 303.07632 \n",
       "L 280.086073 300.312248 \n",
       "L 282.850375 299.144378 \n",
       "L 285.910853 299.165182 \n",
       "L 288.872606 295.120671 \n",
       "L 291.933083 289.390187 \n",
       "L 294.894836 288.509297 \n",
       "L 297.955314 290.20439 \n",
       "L 301.015791 288.896023 \n",
       "L 303.977544 286.223431 \n",
       "L 307.038022 283.784812 \n",
       "L 309.999774 276.338146 \n",
       "L 313.060252 259.917864 \n",
       "L 318.885032 254.058567 \n",
       "L 321.94551 245.426078 \n",
       "L 324.907262 226.69428 \n",
       "L 327.96774 219.045845 \n",
       "L 330.929493 227.280495 \n",
       "L 333.98997 208.747047 \n",
       "L 337.050448 187.436133 \n",
       "L 340.012201 177.932444 \n",
       "L 343.072678 166.462641 \n",
       "L 346.034431 197.326262 \n",
       "L 349.094909 186.218106 \n",
       "L 352.155387 211.244658 \n",
       "L 355.018414 212.237832 \n",
       "L 358.078892 237.197698 \n",
       "L 361.040644 230.916622 \n",
       "L 364.101122 238.3194 \n",
       "L 367.062875 258.189999 \n",
       "L 370.123352 257.060887 \n",
       "L 373.18383 267.843305 \n",
       "L 376.145583 270.795467 \n",
       "L 379.20606 286.896851 \n",
       "L 382.167813 282.839515 \n",
       "L 385.228291 284.274416 \n",
       "L 388.288768 279.433941 \n",
       "L 391.053071 276.806662 \n",
       "L 394.113549 268.531829 \n",
       "L 397.075301 265.557723 \n",
       "L 400.135779 261.130192 \n",
       "L 403.097531 251.827417 \n",
       "L 406.158009 238.926134 \n",
       "L 409.218487 260.138158 \n",
       "L 412.18024 256.955157 \n",
       "L 415.240717 250.787506 \n",
       "L 418.20247 245.103474 \n",
       "L 421.262948 242.771155 \n",
       "L 424.323425 250.974456 \n",
       "L 427.087728 249.189023 \n",
       "L 430.148205 247.559763 \n",
       "L 433.109958 254.356662 \n",
       "L 436.170436 262.292362 \n",
       "L 439.132188 267.814806 \n",
       "L 442.192666 260.999953 \n",
       "L 445.253144 260.962905 \n",
       "L 448.214896 260.48242 \n",
       "L 451.275374 251.272266 \n",
       "L 454.237127 255.793842 \n",
       "L 457.297604 256.138674 \n",
       "L 460.358082 256.634264 \n",
       "L 463.122384 253.375172 \n",
       "L 466.182862 252.717996 \n",
       "L 469.144615 253.191072 \n",
       "L 472.205092 257.979964 \n",
       "L 475.166845 257.449607 \n",
       "L 478.227323 259.169493 \n",
       "L 481.287801 262.99941 \n",
       "L 484.249553 268.930524 \n",
       "L 487.310031 265.823329 \n",
       "L 493.332261 273.484589 \n",
       "L 496.392739 270.828811 \n",
       "L 499.255766 266.956431 \n",
       "L 502.316244 271.678637 \n",
       "L 505.277997 267.873228 \n",
       "L 508.338474 268.559758 \n",
       "L 511.300227 272.743342 \n",
       "L 514.360705 276.214463 \n",
       "L 517.421182 277.813515 \n",
       "L 520.382935 276.712047 \n",
       "L 523.443413 277.204786 \n",
       "L 526.405165 279.734316 \n",
       "L 529.465643 271.497956 \n",
       "L 532.526121 268.183862 \n",
       "L 535.290423 268.748988 \n",
       "L 538.350901 272.424443 \n",
       "L 541.312654 274.097592 \n",
       "L 544.373131 270.601392 \n",
       "L 547.334884 279.760249 \n",
       "L 550.395362 279.344456 \n",
       "L 553.455839 276.36408 \n",
       "L 556.417592 274.190212 \n",
       "L 559.47807 275.132088 \n",
       "L 562.439822 272.88384 \n",
       "L 565.5003 275.862506 \n",
       "L 568.560778 278.225034 \n",
       "L 571.32508 277.563298 \n",
       "L 574.385558 278.218479 \n",
       "L 577.34731 278.416544 \n",
       "L 583.369541 277.790431 \n",
       "L 586.430018 273.423602 \n",
       "L 589.490496 272.977885 \n",
       "L 592.452249 268.798006 \n",
       "L 595.512726 267.193253 \n",
       "L 598.474479 259.70783 \n",
       "L 601.534957 243.981202 \n",
       "L 604.595434 244.674287 \n",
       "L 607.359737 241.826144 \n",
       "L 610.420215 229.355188 \n",
       "L 613.381967 209.584334 \n",
       "L 616.442445 204.737019 \n",
       "L 619.404197 214.270347 \n",
       "L 622.464675 231.753909 \n",
       "L 625.525153 244.798825 \n",
       "L 628.486905 249.165085 \n",
       "L 631.547383 239.76684 \n",
       "L 634.509136 237.975993 \n",
       "L 637.569613 235.303401 \n",
       "L 640.630091 258.147251 \n",
       "L 643.493119 259.561348 \n",
       "L 646.553596 250.557523 \n",
       "L 649.515349 252.427026 \n",
       "L 652.575827 253.045444 \n",
       "L 655.537579 252.675248 \n",
       "L 658.598057 251.258017 \n",
       "L 661.658535 248.232898 \n",
       "L 664.620287 250.535294 \n",
       "L 667.680765 247.80542 \n",
       "L 670.642518 243.54375 \n",
       "L 673.702995 247.71565 \n",
       "L 676.763473 246.133126 \n",
       "L 679.527776 243.780288 \n",
       "L 682.588253 244.328029 \n",
       "L 685.550006 246.261655 \n",
       "L 688.610484 247.329779 \n",
       "L 694.632714 242.888284 \n",
       "L 697.693192 240.386683 \n",
       "L 700.654944 240.724961 \n",
       "L 703.715422 239.459626 \n",
       "L 706.677175 241.629789 \n",
       "L 709.737652 241.915344 \n",
       "L 712.79813 236.96629 \n",
       "L 715.562432 243.276434 \n",
       "L 721.584663 248.325803 \n",
       "L 724.64514 247.948482 \n",
       "L 727.606893 255.017542 \n",
       "L 730.667371 254.191655 \n",
       "L 733.727848 258.499208 \n",
       "L 736.689601 255.760499 \n",
       "L 739.750079 261.989422 \n",
       "L 742.711831 262.405216 \n",
       "L 745.772309 265.092342 \n",
       "L 748.832787 262.50838 \n",
       "L 751.597089 252.352075 \n",
       "L 754.657567 248.082711 \n",
       "L 757.619319 248.436662 \n",
       "L 760.679797 253.556138 \n",
       "L 763.64155 251.271126 \n",
       "L 769.762505 253.91123 \n",
       "L 772.724258 253.371182 \n",
       "L 775.784736 252.690923 \n",
       "L 778.746488 254.317619 \n",
       "L 781.806966 249.240891 \n",
       "L 784.867444 251.338097 \n",
       "L 787.730471 254.080511 \n",
       "L 790.790949 257.785319 \n",
       "L 793.752701 254.656751 \n",
       "L 796.813179 254.877045 \n",
       "L 799.774932 251.106119 \n",
       "L 802.835409 241.834408 \n",
       "L 805.895887 239.392939 \n",
       "L 808.85764 244.455133 \n",
       "L 811.918117 244.270462 \n",
       "L 814.87987 239.504654 \n",
       "L 817.940348 237.187438 \n",
       "L 821.000825 236.902453 \n",
       "L 823.765128 236.161206 \n",
       "L 826.825606 238.075452 \n",
       "L 829.787358 237.934385 \n",
       "L 832.847836 233.128963 \n",
       "L 835.809589 233.820907 \n",
       "L 838.870066 239.345062 \n",
       "L 841.930544 235.167748 \n",
       "L 844.892297 234.477228 \n",
       "L 847.952774 235.070853 \n",
       "L 850.914527 234.599202 \n",
       "L 853.975005 232.436449 \n",
       "L 857.035482 240.368729 \n",
       "L 859.799785 237.494082 \n",
       "L 865.822015 249.328096 \n",
       "L 868.882493 245.356256 \n",
       "L 871.844245 239.309154 \n",
       "L 874.904723 243.452202 \n",
       "L 877.965201 244.90849 \n",
       "L 880.926953 249.974033 \n",
       "L 883.987431 253.704712 \n",
       "L 886.949184 246.356289 \n",
       "L 890.009661 248.125406 \n",
       "L 893.070139 243.382922 \n",
       "L 895.834442 242.700778 \n",
       "L 898.894919 242.893004 \n",
       "L 901.856672 241.456266 \n",
       "L 904.91715 244.839336 \n",
       "L 907.878902 244.910642 \n",
       "L 910.93938 242.374911 \n",
       "L 913.999858 247.252822 \n",
       "L 916.96161 247.52074 \n",
       "L 920.022088 250.134192 \n",
       "L 922.98384 249.823498 \n",
       "L 926.044318 251.38345 \n",
       "L 926.044318 251.38345 \n",
       "\" clip-path=\"url(#p8d3d213286)\" style=\"fill: none; stroke: #d62728; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_3\">\n",
       "    <path d=\"M 20.5625 339.84 \n",
       "L 20.5625 7.2 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_4\">\n",
       "    <path d=\"M 969.1625 339.84 \n",
       "L 969.1625 7.2 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_5\">\n",
       "    <path d=\"M 20.5625 339.84 \n",
       "L 969.1625 339.84 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"patch_6\">\n",
       "    <path d=\"M 20.5625 7.2 \n",
       "L 969.1625 7.2 \n",
       "\" style=\"fill: none; stroke: #000000; stroke-width: 0.8; stroke-linejoin: miter; stroke-linecap: square\"/>\n",
       "   </g>\n",
       "   <g id=\"legend_1\">\n",
       "    <g id=\"patch_7\">\n",
       "     <path d=\"M 27.5625 74.190625 \n",
       "L 120.921875 74.190625 \n",
       "Q 122.921875 74.190625 122.921875 72.190625 \n",
       "L 122.921875 14.2 \n",
       "Q 122.921875 12.2 120.921875 12.2 \n",
       "L 27.5625 12.2 \n",
       "Q 25.5625 12.2 25.5625 14.2 \n",
       "L 25.5625 72.190625 \n",
       "Q 25.5625 74.190625 27.5625 74.190625 \n",
       "z\n",
       "\" style=\"fill: #ffffff; opacity: 0.8; stroke: #cccccc; stroke-linejoin: miter\"/>\n",
       "    </g>\n",
       "    <g id=\"line2d_37\">\n",
       "     <path d=\"M 29.5625 20.298437 \n",
       "L 39.5625 20.298437 \n",
       "L 49.5625 20.298437 \n",
       "\" style=\"fill: none; stroke: #1f77b4; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "    </g>\n",
       "    <g id=\"text_17\">\n",
       "     <!-- My_portfolio -->\n",
       "     <g transform=\"translate(57.5625 23.798437) scale(0.1 -0.1)\">\n",
       "      <defs>\n",
       "       <path id=\"DejaVuSans-4d\" d=\"M 628 4666 \n",
       "L 1569 4666 \n",
       "L 2759 1491 \n",
       "L 3956 4666 \n",
       "L 4897 4666 \n",
       "L 4897 0 \n",
       "L 4281 0 \n",
       "L 4281 4097 \n",
       "L 3078 897 \n",
       "L 2444 897 \n",
       "L 1241 4097 \n",
       "L 1241 0 \n",
       "L 628 0 \n",
       "L 628 4666 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-79\" d=\"M 2059 -325 \n",
       "Q 1816 -950 1584 -1140 \n",
       "Q 1353 -1331 966 -1331 \n",
       "L 506 -1331 \n",
       "L 506 -850 \n",
       "L 844 -850 \n",
       "Q 1081 -850 1212 -737 \n",
       "Q 1344 -625 1503 -206 \n",
       "L 1606 56 \n",
       "L 191 3500 \n",
       "L 800 3500 \n",
       "L 1894 763 \n",
       "L 2988 3500 \n",
       "L 3597 3500 \n",
       "L 2059 -325 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-5f\" d=\"M 3263 -1063 \n",
       "L 3263 -1509 \n",
       "L -63 -1509 \n",
       "L -63 -1063 \n",
       "L 3263 -1063 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-70\" d=\"M 1159 525 \n",
       "L 1159 -1331 \n",
       "L 581 -1331 \n",
       "L 581 3500 \n",
       "L 1159 3500 \n",
       "L 1159 2969 \n",
       "Q 1341 3281 1617 3432 \n",
       "Q 1894 3584 2278 3584 \n",
       "Q 2916 3584 3314 3078 \n",
       "Q 3713 2572 3713 1747 \n",
       "Q 3713 922 3314 415 \n",
       "Q 2916 -91 2278 -91 \n",
       "Q 1894 -91 1617 61 \n",
       "Q 1341 213 1159 525 \n",
       "z\n",
       "M 3116 1747 \n",
       "Q 3116 2381 2855 2742 \n",
       "Q 2594 3103 2138 3103 \n",
       "Q 1681 3103 1420 2742 \n",
       "Q 1159 2381 1159 1747 \n",
       "Q 1159 1113 1420 752 \n",
       "Q 1681 391 2138 391 \n",
       "Q 2594 391 2855 752 \n",
       "Q 3116 1113 3116 1747 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-6f\" d=\"M 1959 3097 \n",
       "Q 1497 3097 1228 2736 \n",
       "Q 959 2375 959 1747 \n",
       "Q 959 1119 1226 758 \n",
       "Q 1494 397 1959 397 \n",
       "Q 2419 397 2687 759 \n",
       "Q 2956 1122 2956 1747 \n",
       "Q 2956 2369 2687 2733 \n",
       "Q 2419 3097 1959 3097 \n",
       "z\n",
       "M 1959 3584 \n",
       "Q 2709 3584 3137 3096 \n",
       "Q 3566 2609 3566 1747 \n",
       "Q 3566 888 3137 398 \n",
       "Q 2709 -91 1959 -91 \n",
       "Q 1206 -91 779 398 \n",
       "Q 353 888 353 1747 \n",
       "Q 353 2609 779 3096 \n",
       "Q 1206 3584 1959 3584 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-72\" d=\"M 2631 2963 \n",
       "Q 2534 3019 2420 3045 \n",
       "Q 2306 3072 2169 3072 \n",
       "Q 1681 3072 1420 2755 \n",
       "Q 1159 2438 1159 1844 \n",
       "L 1159 0 \n",
       "L 581 0 \n",
       "L 581 3500 \n",
       "L 1159 3500 \n",
       "L 1159 2956 \n",
       "Q 1341 3275 1631 3429 \n",
       "Q 1922 3584 2338 3584 \n",
       "Q 2397 3584 2469 3576 \n",
       "Q 2541 3569 2628 3553 \n",
       "L 2631 2963 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-74\" d=\"M 1172 4494 \n",
       "L 1172 3500 \n",
       "L 2356 3500 \n",
       "L 2356 3053 \n",
       "L 1172 3053 \n",
       "L 1172 1153 \n",
       "Q 1172 725 1289 603 \n",
       "Q 1406 481 1766 481 \n",
       "L 2356 481 \n",
       "L 2356 0 \n",
       "L 1766 0 \n",
       "Q 1100 0 847 248 \n",
       "Q 594 497 594 1153 \n",
       "L 594 3053 \n",
       "L 172 3053 \n",
       "L 172 3500 \n",
       "L 594 3500 \n",
       "L 594 4494 \n",
       "L 1172 4494 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-66\" d=\"M 2375 4863 \n",
       "L 2375 4384 \n",
       "L 1825 4384 \n",
       "Q 1516 4384 1395 4259 \n",
       "Q 1275 4134 1275 3809 \n",
       "L 1275 3500 \n",
       "L 2222 3500 \n",
       "L 2222 3053 \n",
       "L 1275 3053 \n",
       "L 1275 0 \n",
       "L 697 0 \n",
       "L 697 3053 \n",
       "L 147 3053 \n",
       "L 147 3500 \n",
       "L 697 3500 \n",
       "L 697 3744 \n",
       "Q 697 4328 969 4595 \n",
       "Q 1241 4863 1831 4863 \n",
       "L 2375 4863 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-6c\" d=\"M 603 4863 \n",
       "L 1178 4863 \n",
       "L 1178 0 \n",
       "L 603 0 \n",
       "L 603 4863 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-69\" d=\"M 603 3500 \n",
       "L 1178 3500 \n",
       "L 1178 0 \n",
       "L 603 0 \n",
       "L 603 3500 \n",
       "z\n",
       "M 603 4863 \n",
       "L 1178 4863 \n",
       "L 1178 4134 \n",
       "L 603 4134 \n",
       "L 603 4863 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      </defs>\n",
       "      <use xlink:href=\"#DejaVuSans-4d\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-79\" x=\"86.279297\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-5f\" x=\"145.458984\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-70\" x=\"195.458984\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-6f\" x=\"258.935547\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-72\" x=\"320.117188\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-74\" x=\"361.230469\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-66\" x=\"400.439453\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-6f\" x=\"435.644531\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-6c\" x=\"496.826172\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-69\" x=\"524.609375\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-6f\" x=\"552.392578\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"line2d_38\">\n",
       "     <path d=\"M 29.5625 35.254687 \n",
       "L 39.5625 35.254687 \n",
       "L 49.5625 35.254687 \n",
       "\" style=\"fill: none; stroke: #ff7f0e; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "    </g>\n",
       "    <g id=\"text_18\">\n",
       "     <!-- Pmax -->\n",
       "     <g transform=\"translate(57.5625 38.754687) scale(0.1 -0.1)\">\n",
       "      <defs>\n",
       "       <path id=\"DejaVuSans-50\" d=\"M 1259 4147 \n",
       "L 1259 2394 \n",
       "L 2053 2394 \n",
       "Q 2494 2394 2734 2622 \n",
       "Q 2975 2850 2975 3272 \n",
       "Q 2975 3691 2734 3919 \n",
       "Q 2494 4147 2053 4147 \n",
       "L 1259 4147 \n",
       "z\n",
       "M 628 4666 \n",
       "L 2053 4666 \n",
       "Q 2838 4666 3239 4311 \n",
       "Q 3641 3956 3641 3272 \n",
       "Q 3641 2581 3239 2228 \n",
       "Q 2838 1875 2053 1875 \n",
       "L 1259 1875 \n",
       "L 1259 0 \n",
       "L 628 0 \n",
       "L 628 4666 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-6d\" d=\"M 3328 2828 \n",
       "Q 3544 3216 3844 3400 \n",
       "Q 4144 3584 4550 3584 \n",
       "Q 5097 3584 5394 3201 \n",
       "Q 5691 2819 5691 2113 \n",
       "L 5691 0 \n",
       "L 5113 0 \n",
       "L 5113 2094 \n",
       "Q 5113 2597 4934 2840 \n",
       "Q 4756 3084 4391 3084 \n",
       "Q 3944 3084 3684 2787 \n",
       "Q 3425 2491 3425 1978 \n",
       "L 3425 0 \n",
       "L 2847 0 \n",
       "L 2847 2094 \n",
       "Q 2847 2600 2669 2842 \n",
       "Q 2491 3084 2119 3084 \n",
       "Q 1678 3084 1418 2786 \n",
       "Q 1159 2488 1159 1978 \n",
       "L 1159 0 \n",
       "L 581 0 \n",
       "L 581 3500 \n",
       "L 1159 3500 \n",
       "L 1159 2956 \n",
       "Q 1356 3278 1631 3431 \n",
       "Q 1906 3584 2284 3584 \n",
       "Q 2666 3584 2933 3390 \n",
       "Q 3200 3197 3328 2828 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-61\" d=\"M 2194 1759 \n",
       "Q 1497 1759 1228 1600 \n",
       "Q 959 1441 959 1056 \n",
       "Q 959 750 1161 570 \n",
       "Q 1363 391 1709 391 \n",
       "Q 2188 391 2477 730 \n",
       "Q 2766 1069 2766 1631 \n",
       "L 2766 1759 \n",
       "L 2194 1759 \n",
       "z\n",
       "M 3341 1997 \n",
       "L 3341 0 \n",
       "L 2766 0 \n",
       "L 2766 531 \n",
       "Q 2569 213 2275 61 \n",
       "Q 1981 -91 1556 -91 \n",
       "Q 1019 -91 701 211 \n",
       "Q 384 513 384 1019 \n",
       "Q 384 1609 779 1909 \n",
       "Q 1175 2209 1959 2209 \n",
       "L 2766 2209 \n",
       "L 2766 2266 \n",
       "Q 2766 2663 2505 2880 \n",
       "Q 2244 3097 1772 3097 \n",
       "Q 1472 3097 1187 3025 \n",
       "Q 903 2953 641 2809 \n",
       "L 641 3341 \n",
       "Q 956 3463 1253 3523 \n",
       "Q 1550 3584 1831 3584 \n",
       "Q 2591 3584 2966 3190 \n",
       "Q 3341 2797 3341 1997 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-78\" d=\"M 3513 3500 \n",
       "L 2247 1797 \n",
       "L 3578 0 \n",
       "L 2900 0 \n",
       "L 1881 1375 \n",
       "L 863 0 \n",
       "L 184 0 \n",
       "L 1544 1831 \n",
       "L 300 3500 \n",
       "L 978 3500 \n",
       "L 1906 2253 \n",
       "L 2834 3500 \n",
       "L 3513 3500 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      </defs>\n",
       "      <use xlink:href=\"#DejaVuSans-50\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-6d\" x=\"60.302734\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-61\" x=\"157.714844\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-78\" x=\"218.994141\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"line2d_39\">\n",
       "     <path d=\"M 29.5625 49.932812 \n",
       "L 39.5625 49.932812 \n",
       "L 49.5625 49.932812 \n",
       "\" style=\"fill: none; stroke: #2ca02c; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "    </g>\n",
       "    <g id=\"text_19\">\n",
       "     <!-- P1 -->\n",
       "     <g transform=\"translate(57.5625 53.432812) scale(0.1 -0.1)\">\n",
       "      <use xlink:href=\"#DejaVuSans-50\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-31\" x=\"60.302734\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "    <g id=\"line2d_40\">\n",
       "     <path d=\"M 29.5625 64.610937 \n",
       "L 39.5625 64.610937 \n",
       "L 49.5625 64.610937 \n",
       "\" style=\"fill: none; stroke: #d62728; stroke-width: 1.5; stroke-linecap: square\"/>\n",
       "    </g>\n",
       "    <g id=\"text_20\">\n",
       "     <!-- Market -->\n",
       "     <g transform=\"translate(57.5625 68.110937) scale(0.1 -0.1)\">\n",
       "      <defs>\n",
       "       <path id=\"DejaVuSans-6b\" d=\"M 581 4863 \n",
       "L 1159 4863 \n",
       "L 1159 1991 \n",
       "L 2875 3500 \n",
       "L 3609 3500 \n",
       "L 1753 1863 \n",
       "L 3688 0 \n",
       "L 2938 0 \n",
       "L 1159 1709 \n",
       "L 1159 0 \n",
       "L 581 0 \n",
       "L 581 4863 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "       <path id=\"DejaVuSans-65\" d=\"M 3597 1894 \n",
       "L 3597 1613 \n",
       "L 953 1613 \n",
       "Q 991 1019 1311 708 \n",
       "Q 1631 397 2203 397 \n",
       "Q 2534 397 2845 478 \n",
       "Q 3156 559 3463 722 \n",
       "L 3463 178 \n",
       "Q 3153 47 2828 -22 \n",
       "Q 2503 -91 2169 -91 \n",
       "Q 1331 -91 842 396 \n",
       "Q 353 884 353 1716 \n",
       "Q 353 2575 817 3079 \n",
       "Q 1281 3584 2069 3584 \n",
       "Q 2775 3584 3186 3129 \n",
       "Q 3597 2675 3597 1894 \n",
       "z\n",
       "M 3022 2063 \n",
       "Q 3016 2534 2758 2815 \n",
       "Q 2500 3097 2075 3097 \n",
       "Q 1594 3097 1305 2825 \n",
       "Q 1016 2553 972 2059 \n",
       "L 3022 2063 \n",
       "z\n",
       "\" transform=\"scale(0.015625)\"/>\n",
       "      </defs>\n",
       "      <use xlink:href=\"#DejaVuSans-4d\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-61\" x=\"86.279297\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-72\" x=\"147.558594\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-6b\" x=\"188.671875\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-65\" x=\"242.957031\"/>\n",
       "      <use xlink:href=\"#DejaVuSans-74\" x=\"304.480469\"/>\n",
       "     </g>\n",
       "    </g>\n",
       "   </g>\n",
       "  </g>\n",
       " </g>\n",
       " <defs>\n",
       "  <clipPath id=\"p8d3d213286\">\n",
       "   <rect x=\"20.5625\" y=\"7.2\" width=\"948.6\" height=\"332.64\"/>\n",
       "  </clipPath>\n",
       " </defs>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<Figure size 1700x600 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig=plt.figure(figsize=(17,6))\n",
    "plt.plot(MYPORT['My_portfolio_price'],label='My_portfolio')\n",
    "plt.plot(MYPORT['Pmax_price'],label='Pmax')\n",
    "plt.plot(MYPORT['P1_price'],label='P1')\n",
    "plt.plot(MYPORT['Market_price'],label='Market')\n",
    "plt.legend()\n",
    "plt.grid()\n",
    "plt.show();"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 最大回测"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 202,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "最大回撤为： -0.5167687396538915\n"
     ]
    }
   ],
   "source": [
    "# 计算累计收益率\n",
    "MYPORT['cumlative_return']=(1+MYPORT['My_portfolio']).cumprod()\n",
    "\n",
    "# 计算滚动最大值\n",
    "MYPORT['roll_max']=MYPORT['cumlative_return'].cummax()\n",
    "\n",
    "# 计算回撤\n",
    "MYPORT['drawdown']=MYPORT['cumlative_return']/MYPORT['roll_max']-1\n",
    "\n",
    "# 计算最大回撤\n",
    "max_drawdown=MYPORT['drawdown'].min()\n",
    "print('最大回撤为：',max_drawdown)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 204,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "最大回撤开始时间为： 2014-08-31 00:00:00\n",
      "最大回撤结束时间为： 2015-04-30 00:00:00\n"
     ]
    }
   ],
   "source": [
    "#找到最大回测的时间点\n",
    "max_drawdown_time=MYPORT['drawdown'].idxmin()\n",
    "max_drawdown_start=MYPORT.loc[:max_drawdown_time,'cumlative_return'].idxmax()\n",
    "print('最大回撤开始时间为：',max_drawdown_start)\n",
    "print('最大回撤结束时间为：',max_drawdown_time)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
